3

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

10
  • You get the error when you try to generate a new project or while launching an already existing project ? Commented Aug 26, 2019 at 8:29
  • when i try to create a brand new project Commented Aug 26, 2019 at 17:23
  • and what command do you use to create new project ? npx create-react-app your-app ? Commented Aug 27, 2019 at 14:54
  • yes, neither npx create-react-app your-app or create-react-app your-app works Commented Aug 27, 2019 at 18:34
  • have you tried npm uninstall create-react-app before re-installing it ? Commented Aug 27, 2019 at 20:44

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

Comments

0

Just run this code on git bash:

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.