Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

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

Error: Cannot find module 'C:\Users\User\Desktop\NodeJsProject\app.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
    at startup (internal/bootstrap/node.js:285:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
like image 599
istiyak ahamed Milon Avatar asked Nov 29 '18 18:11

istiyak ahamed Milon


4 Answers

For All => Windows, Linux, Mac

  1. Delete the node_modules directory
  2. Delete the package-lock.json file
  3. Run npm install
  4. Run npm start

For Linux

rm -rf node_modules package-lock.json && npm install && npm start
like image 60
Parth kharecha Avatar answered Nov 20 '22 07:11

Parth kharecha


I had the same issue when I first tried on node js.
I noticed this issue was happening to me because I had some .js files with same names in different directories, which were in the same main directory.
I created another directory outside the main project folder, and created a .js file.
After that, it ran fine.
ex- app.js

like image 26
Hashan Gunathilaka Avatar answered Nov 20 '22 06:11

Hashan Gunathilaka


try the following command

remove node_modules and package-lock.json

rm -rf node_modules package-lock.json

then run the following command to install dependencies

npm install

finally, run your package by the following command.

npm start
like image 19
Mohit Rathod Avatar answered Nov 20 '22 06:11

Mohit Rathod


What helped me was to place the .js file that I was working with in a new folder, drag and drop that folder into VS Code (to open the directory directly in VS Code), open the terminal in VS Code, and then simply type node <filename>.js (or in my case node index.js).

I had already installed node on my system, but for whatever reason, I was still getting the error that you've mentioned, even when I typed the direct path to the file i.e. node /desktop/index.js.

So, creating a new folder on my desktop, placing the .js file inside that folder, opening that folder within VS Code, and then typing node index.js in the terminal solved my issue.

like image 8
HappyHands31 Avatar answered Nov 20 '22 07:11

HappyHands31