Enzo
Enzo

Reputation: 31

create-react-app returns an Error: Cannot find module 'react-scripts/scripts/init.js' when executed

when I try to create a react project with both npm and yarn, it shows me the following error:

I tried to reinstall node and make sure it was up to date, as well as create-react-app by running npm install -g create-react-app@latest. I also removed the npm and npm-cache folders and the environment variable, but nothing works for me and I keep getting the same error.

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

Error: Cannot find module 'react-scripts/scripts/init.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at [eval]:2:20
    at Script.runInThisContext (vm.js:122:20)
    at Object.runInThisContext (vm.js:329:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at evalScript (internal/bootstrap/node.js:589:27)

Aborting installation.
  node  has failed.

Deleting generated file... node_modules
Deleting generated file... package.json
Deleting generated file... yarn.lock
Deleting test/ from C:\Users\Esper\projects
Done.

I think the problem arose from restoring my windows 10 to a previous state due to operating system problems, because before restoring it, when I run create-react-app it worked correctly.

create-react-app --version 3.1.1

node -v v10.16.3

npm -v 6.9.0

SO Windows 10 Education

Upvotes: 3

Views: 5047

Answers (3)

Soon Santos
Soon Santos

Reputation: 2219

Maybe it will help somebody else.

This error can happen after you use create-react-app in case you have some invalid character in your path.

Remove charecteres like & from your path.

For example, change from this:

C:\Users\...\Documents\Section 3 Components & Start\my-app

To this:

C:\Users\...\Documents\Section 3 Components Start\my-app

Upvotes: 0

naim
naim

Reputation: 39

Just run this code on git bash:

npm install
npm install react-scripts
npx create-react-app your-app-name

Upvotes: 0

Mihai
Mihai

Reputation: 115

Install a package.json with npm init (press enter till is installed)
After that install react-scripts with npm i react-scripts,
Then you can install react with npx create-react-app your-app.
Change the directory to "your-app"
Run again npm i react-scripts and it should work.

Hope I did not missed a step, let me know if works :)

Upvotes: 4

Related Questions