internal/modules/cjs/loader.js:582 throw err

前端 未结 25 2087
有刺的猬
有刺的猬 2020-11-27 04:24

I\'m getting following Console Error. Error : Cannot find module

Here is the full error i\'m getting in console. What should I do?



        
25条回答
  •  佛祖请我去吃肉
    2020-11-27 05:15

    This error message is easy to reproduce.

    • Open a terminal window.
      (On Windows: WinKey, cmd, Enter. On Linux: Ctrl + Alt + t.)
    • Type npm and hit Enter to see if Node.js is installed.
    • If you get command not found, download at https://nodejs.org/en/download/ and install.
      (On Linux/Ubuntu: sudo apt install nodejs if you prefer.)
    • Type (or paste) node thisFileDoesNotExist.js (and hit Enter).

    On Windows expect to see something similar to:

    internal/modules/cjs/loader.js:969
      throw err;
      ^
    
    Error: Cannot find module [... + a few more lines]
    

    On Linux (Ubuntu 18.04):

    module.js:549
      throw err;
      ^
    
    Error: Cannot find module [...]
    

    I have not tried macOS, but would expect something similar there as well.

    Note: This might happen for no apparent reason when debugging in Visual Studio Code.
    If you get the error inside VScode, see if the answer by HappyHands31 is of any help.


    Finally, to run Node.js in the terminal without an error, in the Windows terminal (command line) try:

    echo console.log('\nHello world!')> hello.js
    node hello.js
    

    In the Linux terminal try:

    echo "console.log('\nHello world\!\n')"> hello.js
    node hello.js
    

    Of course, expect to see the terminal responding:

    Hello world!
    

提交回复
热议问题