nodejs module.js:340 error: cannot find module

前端 未结 21 570
别那么骄傲
别那么骄傲 2021-02-02 06:39

I installed nodejs in C:\\Program Files (x86)\\nodejs

then I created a .js file and saved it in my desktop just to output \'hello world\' in the console:



        
相关标签:
21条回答
  • 2021-02-02 06:55

    I was having the same problem with a server someone had written a while back. It turns out I didn't have a few things installed that the script required.

    This question was helpful to me.

    I ended up being able to use:

    npm install yourMissingDependency 
    

    Although in your instance it may just be a file that it doesn't have a path to. You could try putting that file in the same folder you are running the node script from.

    0 讨论(0)
  • 2021-02-02 06:55

    I had a nearly identical issue, turned out my JS file wasn't actually in the folder I was calling it from, and I had gone one folder too deep. I went up one directory, ran the file, it recognized it, happily ever after.

    Alternatively, if you go one folder up, and it gives you the same error, but about a different module, take that same file in your parent folder and move it into the subfolder you were previously trying to run things from.

    TL;DR- your file or its module(s) is not in the folder you think it is. Go up one level

    0 讨论(0)
  • 2021-02-02 06:59

    I had the same problem then I found that I wasn´t hitting the node server command in the proper directory where the server.js is located.

    Hope this helps.

    0 讨论(0)
  • 2021-02-02 07:01

    Hi fellow Phonegap/Cordova/Ionic developers,

      I solved this issue by doing the following
    
      1. C: drive -> Users -> "username" eg. john -> AppData -> Roaming
    
      2. Inside the "Roaming" folder you need to delete both "npm" and "npm-cache" 
           folder.
    
      3. Now build your project, and it should work
    

    Happy coding!!!

    0 讨论(0)
  • 2021-02-02 07:03

    Restart your command prompt and check your path variable (type: path). If you can't find find nodejs installation dir from output add it to the path variable and remember to restart cdm again...

    0 讨论(0)
  • 2021-02-02 07:05

    I also got this issue and this was due to wrong path that we mention while running. Check your file path and also make sure that there is no space between the name of your directory name.

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