nodejs module.js:340 error: cannot find module

前端 未结 21 571
别那么骄傲
别那么骄傲 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 07:09
    1. Try npm start in Node.js Command Prompt.
    2. Look at the end of the messages - it gives you the path of log file in "Additional Logging Details ..." something like c:\users\MyUser\npm-debug.log
    3. Open this file in Notepad and find the real address of Node.exe : something like C:\\Program Files\\nodejs\\\\node.exe
    4. Try cd to this path
    5. Call node.exe + <full path to your server file.js>

      Server is listening on port 1337 !
      
    0 讨论(0)
  • 2021-02-02 07:10

    I faced the same problem. I just copied the testNode.js file(that contain the test code) and pasted into the root of nodejs directory manually. I tried this command C:\Program Files (x86)\nodejs>node testnode.js Bingo! I received this message.

    enter image description here

    Then I typed this url in a browser and received the message "Hello World". Hope this help somebody.

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

    Faced the same problem while trying to run node-red.

    node <directory structure where js  is located>/red. js
    

    In my case it was :

    node AppData/Roaming/npm/node_modules/node-red/red.js
    
    0 讨论(0)
  • 2021-02-02 07:13

    You need to:

    • Remove the tick of Hide extensions for known file types from Windows Explorer folders option
    • Your file will appear as testNode.js.txt
    • Remove the trailing .txt so as the file to be resolved as JS file

    That's it, now it works!

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

    I had the same problem, but finally I tried copying the Node_modules folder in the same project folder, and it worked.

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

    EDIT: This answer is outdated. With things like Yarn and NPM 5's lockfiles it is now easier to ensure you're dependencies are correct on platforms like Heroku

    I had a similar issue related to node_modules being modified somehow locally but the change was not reflect on Heroku, causing my app to crash. It's relatively easy fix if this is your issue:

    # Remove node_modules
    rm -fr node_modules
    
    # Reinstall packages
    npm i
    
    # Commit changes
    git add node_modules
    git commit -m 'Fix node_modules dependencies.'
    git push heroku master
    

    Hope that helps for others with a similar issue.

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