Internal/modules/cjs/loader.js

How to fix the internal/modules/cjs/loader.js error? I get the following console error. Error : Cannot find module This is the full error I get in the console. What should I do? What many users have in common is that the error in the question appears when the node is refers to a file that does…

How to fix the internal/modules/cjs/loader.js error?

I get the following console error. Error : Cannot find module

This is the full error I get in the 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) 


What many users have in common is that the error in the question appears when the node is refers to a file that does not exist. (!)


I had the same problem when I first tried node js.
I noticed that this problem was occurring to me because I had several .js files with the same name in different directories that were in the same main directory.
I created another directory outside of the main project folder and created the .js file.
After that, everything worked.
ex- app.js.

Another solution to the problem

  • Remove node_modules directory
  • Delete package-lock.json file
  • Run npm install
  • Run npm start

OR

rm -rf node_modules package-lock.json
Then run the following command to install the dependencies

npm install
Finally, start your package by running the following command.

npm start
I had the same error because I had a space at the end of the file name (not a reference, but the actual file name). Once I changed app.js to app.js, everything worked.

Replace the file name with package.json ({'npm': .js}) with the file where your server code runs (it should be app.js, main.js, start.js, server.js, or whatever you choose).

What worked for me was placing the .js file I was working with in a new folder, drag that folder into VS Code (to open the directory directly in VS Code), open a terminal in VS Code, and then just type node .js (or in my case node index.js).

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

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

Make sure you have the correct address path for app.js when running node /app.js. Can’t find

Error: Cannot find module 'C:\Users\User\Desktop\NodeJsProject\app.js'


This strange behavior exists. I just deleted the duplicates and closed the command line to open again in Windows. It worked fine.

The specific .js file was in a subfolder (/ src) of the application, and Terminal was in the general application folder. (Which contains all package files, modules, shared folder, src folder), it was giving this error. src) application solved my problem.

When I used the command below, I also got the same error:

node .function-hello.js
I changed my command to the command below, it worked fine:

node .\function-hello.js
For me, “npm install” from the command line worked again. The command line should be “Run as administrator”.

You need to start the server, use the following command

npm start
or

yarn start
That was an oops. I was running npm start instead of npn start. Too stupid!
The path to the js file you are trying to execute is wrong; you need to type the path and file name you want to execute relative to root where the node is, but what you entered is not where it is.

I typed node redux-basics.js, got a slightly misleading Stack Overflow’ed error message, looked at my filesystem, and had to type node src/redux-basics.js.

The same thing happened to me, I just solved by deleting the “dist” file and re-running the application.

For me, the Node package I was trying to use would only work in an older version of Node.

I was able to fix this by using Homebrew to install an older version of Node:

brew unlink node brew install node@12 echo 'export PATH='/usr/local/opt/node@12/bin:$PATH'' >> ~/.zshrc


In the above commands, you will need to edit the node version and then export the PATH command.

The following commands below solved the problem for me.

npm install node-gyp -g npm install bcrypt -g npm install bcrypt -save
I uninstalled puppeteer, mocha and chai with

npm uninstall puppeteer mocha chai
from the command line, and then reinstall with the

npm install puppeteer mocha chai


And the error message just never showed up!

Similar Posts

Leave a Reply

Your email address will not be published.