5

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: []
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Bader Juma
  • 51
  • 1
  • 4

6 Answers6

1

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)).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sujith Kumar
  • 872
  • 6
  • 19
0

First, try to clear the npm cache:

npm cache clear --force or 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Parth Raval
  • 4,097
  • 3
  • 23
  • 36
0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sheree
  • 1
0

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.

kartik goyal
  • 96
  • 1
  • 3
-5

The error message you provided indicates an issue with the Node.js module loader. This error is typically thrown when a module cannot be loaded or there is a problem with the module's code.

To find a solution to this issue, you can try the following steps:

  1. Verify the module's compatibility with the Node.js version you're using.

  2. Check for syntax mistakes or other problems in the module's code whether it is custom code or a third-party module that you are attempting to load. Verify the module's compatibility with the Node.js version you're using.

  3. Clear the Node.js module cache because it occasionally can lead to conflicts. By removing the node_modules directory and executing npm install once again to reinstall the dependencies, you can attempt clearing the Node.js module cache.

  4. Update Node.js and npm: Ensure you have Node.js and npm installed in their most recent stable versions. This error could occur because of compatibility problems with older versions. For the most recent releases, visit the Node.js website (https://nodejs.org).

  5. Check for incompatible modules: It's conceivable that a module in your project has incompatible versions. To search for duplicate or conflicting dependencies, use the npm ls command.

  6. Reinstall dependencies: If none of the aforementioned solutions work, consider reinstalling all of the project's dependencies by removing the node_modules directory and rerunning tpm install.

If the issue still exists after attempting these solutions, it could be good to share more details about your particular configuration, such as the code that causes the error and the Node.js and npm versions you are running.

  • 3
    This answer looks like ChatGPT – DavidW Jul 06 '23 at 14:09
  • This answer looks like it was generated by an AI (like ChatGPT), not by an actual human being. You should be aware that [posting AI-generated output is officially **BANNED** on Stack Overflow](https://meta.stackoverflow.com/q/421831). If this answer was indeed generated by an AI, then I strongly suggest you delete it before you get yourself into even bigger trouble: **WE TAKE PLAGIARISM SERIOUSLY HERE.** Please read: [Why posting GPT and ChatGPT generated answers is not currently allowed](https://stackoverflow.com/help/gpt-policy). – tchrist Jul 16 '23 at 20:50