I\'m getting following Console Error.
Error : Cannot find module
Here is the full error i\'m getting in console. What should I do?
This error message is easy to reproduce.
cmd, Enter.
On Linux: Ctrl + Alt + t.)npm and hit Enter to see if Node.js is installed.command not found, download at https://nodejs.org/en/download/
and install.sudo apt install nodejs if you prefer.)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!