node.js, Error: Cannot find module 'express'

后端 未结 18 1763
情话喂你
情话喂你 2020-12-02 08:57

I am new to Node.js, try to learn express to build my first web application. I got stuck on my very first sample code and need some help to get it running. Before I post th

相关标签:
18条回答
  • 2020-12-02 09:20

    I've came across a similar problem and in the end it was a matter of some old dependencies that were messing up my Heroku server.

    While at my project's folder I've run:

    npm uninstall
    npm install
    

    I hope it helps

    0 讨论(0)
  • 2020-12-02 09:20

    Have you tried

    npm install
    

    If you're specifically looking for just express

    npm install --save express
    
    0 讨论(0)
  • 2020-12-02 09:21

    It says

     Cannot find module 'express'
    

    Do you have express installed?If not then run this.

     npm install express
    

    And run your program again.

    0 讨论(0)
  • 2020-12-02 09:21

     npm install --save express   
    This worked for me, Just run express.js installation again

    0 讨论(0)
  • 2020-12-02 09:22

    In rare cases, npm cache may get corrupt. For me, what worked was:

    npm cache clean --force
    

    Generally, the package manager will detect corruption and refetch on its own so this is not usually necessary. However, in my case Windows 10 crashed a few times and I suspect this may have been during a fetch operation. Hope it helps someone!

    More information: https://docs.npmjs.com/cli/cache

    0 讨论(0)
  • 2020-12-02 09:25

    Run npm install express body-parser cookie-parser multer --save command in the same directory with your source code nodejs file to resolve this issue. P/s: check your directory after run command to understand more!

    0 讨论(0)
提交回复
热议问题