Bader Juma
Bader Juma

Reputation: 201

Error "node:internal/modules/cjs/loader:1056 throw err;"

I am using Node.js v19.4.0.

When I run npx create-react-app MyApp to create a React project in the Visual Studio Code editor, I get the following error:

node:internal/modules/cjs/loader:1056
  throw err;
  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1053:15)
    at Module._load (node:internal/modules/cjs/loader:898:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:84:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v19.4.0
node:internal/modules/cjs/loader:1056
  throw err;
  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npx-cli.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1053:15)
    at Module._load (node:internal/modules/cjs/loader:898:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:84:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Upvotes: 20

Views: 140996

Answers (9)

Benard Agustin
Benard Agustin

Reputation: 79

if npx create-react-app was working previously just try to reinstall the create-react-app. make sure you install it globally use

npm install -g create-react-app

`

Upvotes: 1

Parth Raval
Parth Raval

Reputation: 4413

First, try to clear the npm cache with:

npm cache clean --force
  • then remove all node_modules folders from the application
  • remove the package-lock.json file from the application
  • Install packages again by using the command npm install
  • then start the application using npm start

If the above solution will not work then, try to remove Node.js and then reinstall.

Upvotes: 18

Shiv
Shiv

Reputation: 1

It is very simple ans but trust me it works!!! Just close everything including vscode and go the exact folder where your node_modules and package.json are located, open it in vscode, and try to hit your command again. I found this through youtube, apparently when we have nested folders, npm is not able to recognize them properly thus causing this issue.

Upvotes: -2

damapass
damapass

Reputation: 23

You can try checking if any of the folders in the path contain problematic characters like '&'. This just happened to me and removing '&' from one of the folder names solved the problem.

Upvotes: 1

Alwin J Thomas
Alwin J Thomas

Reputation: 21

1.uninstall and reinstall node

2.delete the folder

C:\Users{Username}\AppData\Roaming\npm

3.reinstall npm using the command

npm install -g npm

4.run any npm command again

Upvotes: 1

kartik goyal
kartik goyal

Reputation: 126

I was facing the same issue after changing the folder name.

The issue is happening because of babel-node and cjs/loader library as per error message they store project cache data.

One solution is clearing the cache but was not able to that even after removing node module but found another way.

As react reconcilation algorithm rerender the component after any change inside the component having this in mind implements the same logic. I added a new empty line at the top of the appjs file above the line where I am getting the error message and started the app again.

App started without throwing any error. It worked.

Upvotes: 0

Sheree
Sheree

Reputation: 1

In my case, I had to npm install the missing "modules" with was "npm install validator" and "npm install is-empty.

The required stack pointed in the direction... It took all of yesterday to figure it out.

Upvotes: 0

Konstantin Krasser
Konstantin Krasser

Reputation: 11

Downgrade to an LTS-supported version!

brew install node@18

brew link --overwrite node@18

node --version

worked for me (MacBook M1; macOS v13.1 (Ventura)).

Upvotes: 0

Sujith Kumar
Sujith Kumar

Reputation: 623

The first solution is to uninstall Node.js and npm and then reinstall them.

Or it might be because of an incorrect node_modules path. Please check the path and make sure it is correct.

Upvotes: 1

Related Questions