Reputation: 201
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
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
Reputation: 4413
First, try to clear the npm cache with:
npm cache clean --force
npm install
npm start
If the above solution will not work then, try to remove Node.js and then reinstall.
Upvotes: 18
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
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
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
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
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
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
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