108

I have a project who I didn't touch for 2 weeks. I take it back and now when I try to run npm start I got this error.

> react-scripts start

sh: react-scripts: command not found

npm ERR! Darwin 16.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.7.0
npm ERR! npm  v3.10.3
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! UpScore@0.6.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the UpScore@0.6.0 start script 'react-scripts start'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the UpScore package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     react-scripts start
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs UpScore
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls UpScore
npm ERR! There is likely additional logging output above.
  • node 6.7.0
  • npm 3.10.3
  • mac sierra 10.12

package.json

{
  "name": "UpScore",
  "version": "0.6.0",
  "private": true,
  "devDependencies": {
    "react-addons-test-utils": "^15.3.1",
    "react-scripts": "0.4.1",
    "react-test-renderer": "^15.3.1",
    "redux-logger": "^2.6.1"
  },
  "dependencies": {
    "@yoshokatana/medium-button": "^1.1.0",
    "axios": "^0.14.0",
    "bcrypt": "^0.8.7",
    "bcrypt-nodejs": "0.0.3",
    "bcryptjs": "^2.3.0",
    "body-parser": "^1.15.2",
    "connect-flash": "^0.1.1",
    "cookie-parser": "^1.4.3",
    "draft-js": "^0.8.1",
    "draft-js-editor": "^1.7.2",
    "draft-js-export-html": "^0.4.0",
    "ejs": "^2.5.2",
    "email-verification": "^0.4.5",
    "express": "^4.14.0",
    "express-session": "^1.14.1",
    "flexboxgrid": "^6.3.1",
    "highlight.js": "^9.6.0",
    "immutable": "^3.8.1",
    "katex": "^0.6.0",
    "lodash": "^4.15.0",
    "markdown-it-mathjax": "^1.0.3",
    "material-ui": "^0.15.4",
    "medium-editor": "^5.22.0",
    "minutes-seconds-milliseconds": "^1.0.3",
    "moment": "^2.15.0",
    "moment-duration-format": "^1.3.0",
    "mongod": "^1.3.0",
    "mongodb": "^2.2.9",
    "mongoose": "^4.6.0",
    "monk": "^3.1.2",
    "morgan": "^1.7.0",
    "normalize.css": "^3.0.3",
    "passport": "^0.3.2",
    "passport-local": "^1.0.0",
    "react": "^15.3.1",
    "react-dom": "^15.3.1",
    "react-markdown": "^2.4.2",
    "react-medium-editor": "^1.8.1",
    "react-redux": "^4.4.5",
    "react-redux-form": "^0.14.5",
    "react-rich-markdown": "^1.0.1",
    "react-router": "^2.7.0",
    "react-router-redux": "^4.0.5",
    "react-tap-event-plugin": "^1.0.0",
    "react-tinymce": "^0.5.1",
    "redux": "^3.6.0",
    "redux-form": "^6.0.5",
    "redux-form-material-ui": "^4.0.1",
    "redux-promise-middleware": "^4.0.0",
    "redux-thunk": "^2.1.0",
    "reselect": "^2.5.3",
    "screenfull": "^3.0.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "start:prod": "pushstate-server build",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "server": "cd client/api && pm2 start server.js --watch",
    "proxy": "http://128.199.139.144:3000"
  },
  "eslintConfig": {
    "extends": "./node_modules/react-scripts/config/eslint.js"
  }
}

I try to clone my repos too and get the same error. If someone can give me some way to find what happen. Thank you

EQuimper
  • 5,811
  • 8
  • 29
  • 42
  • 4
    Have you tried removing your `node_modules` and running `npm install` again? – Nitsew Oct 10 '16 at 13:53
  • 1
    Yes I clean the node_modules and npm install. I got no error in the npm install. – EQuimper Oct 10 '16 at 13:54
  • I have use this command `rm -rf node_modules/ && npm cache clean && npm install` – EQuimper Oct 10 '16 at 13:56
  • can you show us your `npm start` command ? – Steeve Pitis Oct 10 '16 at 13:57
  • I have add the package.json file – EQuimper Oct 10 '16 at 14:00
  • No I have just try and look like he want to run but I got this `Could not find a required file. Name: index.html` And they search on public ? Why I got all this error now when last week he was working ? You think cause of new update of create-react-app ? – EQuimper Oct 10 '16 at 14:21
  • @EQuimper: It looks like Nitsew (you disagree with) and accepted user (you agree with) answer are the same, or am I missing something? – HoldOffHunger Jul 23 '18 at 14:23
  • I don't know how but after adding `C:\Windows\System32` in global `path` environment variable has fixed it. Source: [Below answer](https://stackoverflow.com/a/61525828/8494462). I opened a [bug](https://github.com/facebook/create-react-app/issues/9200) too at github in `create-react-app` – Shivam Sharma Jun 22 '20 at 17:28

24 Answers24

282

Author of Create React App checking in.

You absolutely should not be installing react-scripts globally.
You also don't need ./node_modules/react-scripts/bin/ in package.json as this answer implies.

If you see this:

npm ERR! UpScore@0.6.0 start: `react-scripts start`
npm ERR! spawn ENOENT

It just means something went wrong when dependencies were installed the first time.

I suggest doing these three steps:

  1. npm install -g npm@latest to update npm because it is sometimes buggy.
  2. rm -rf node_modules to remove the existing modules.
  3. npm install to re-install the project dependencies.

This should fix the problem.
If it doesn't, please file an issue with a link to your project and versions of Node and npm.

Community
  • 1
  • 1
Dan Abramov
  • 264,556
  • 84
  • 409
  • 511
  • That did not work for me. npm v3.3.1; node v6.9.1. I am on Windows and this problem started after I did a system restore to roll back a few weeks to fix another problem. – MartinDuo Nov 22 '16 at 14:39
  • 3
    P.S.: Running your steps, I get this error. 'rm' is not recognized as an internal or external command. I think the system restore removed something needed to run these node commands, but I have no clue. – MartinDuo Nov 22 '16 at 14:43
  • 3
    P.P.S. I manually deleted the node_modules folder and ran the npm install. Now it works! Thanks for the clue about replacing the node_modules. – MartinDuo Nov 22 '16 at 14:54
  • 1
    That still doesn't work for me!! Actually it is failing when I have deployed on Heroku! – aman_novice Mar 15 '17 at 06:46
  • Hey @dan-abromov what about same error in bitbucket CI, what's your suggestions to fix that? – Necmttn Jul 09 '17 at 16:48
  • I manually deleted the node_modules folder and tried 'npm install', but I got a new node_modules folder with just a .staging folder inside. I could only fix it by creating an entirely new create-react-app instance and copying the entire node_modules folder into my existing app – peter.swallow Jul 14 '17 at 06:18
  • @aman_novice, did you ever get a fix for this? For me it's working locally but fails on heroku deploy. – deathandtaxes Sep 27 '17 at 08:41
  • @deathandtaxes: dude, i dont actually remember what this issue was. I ended depoying the app on AWS after breaking my head with this issue for hours. – aman_novice Sep 27 '17 at 15:46
  • Same, everything works locally. I can build. But deploying to Heroku fails. ``` > react-scripts build sh: 1: react-scripts: not found npm ERR! file sh npm ERR! code ELIFECYCLE npm ERR! errno ENOENT npm ERR! syscall spawn ``` – TheJKFever Jan 15 '18 at 09:43
  • Thanks it works (1) del node_modules (2) npm install – joseAndresGomezTovar Feb 25 '18 at 09:15
  • npm install rimraf -g and rimraf node_modules to remove the node-modules on window pc command line. – Pir Abdul Dec 21 '18 at 09:58
  • It did not work for me. Using vagrant ubuntu in a Mac computer. – kta Apr 03 '19 at 05:43
  • This fixed my issue. Was working one night and then the next day wasn't working with any brand new project at all. Thanks! – Harlin Apr 11 '19 at 12:30
  • @MartinDuo 'rm' is a linux command. You may have had a bash shell or git bash installed. Try to install or re-install a bash shell for windows. rm just removes files or folders - the instructions above are just telling you update to the latest NPM, delete the node_modules folder and reinstall the project dependencies. – John Jun 13 '19 at 19:23
  • I just needed the first line run in my Visual Studio and then it fixed itself on the next build. cheers. – Andrew Smith Dec 21 '19 at 12:20
  • This worked for me. Perfect. The problem is: worked FOUR TIMES :D Anyone know why this is happening so I can create a new projects without this issue? I'm new to React. I'm testing and creating new apps to learn. And need to reinstall twice each new project :( Thanks guys! – Natacha Apr 18 '20 at 17:44
  • mine didnt work, then i realise i added .env config BROWSER=0 (but instead i need to set it to BROWSER=none) and its fixed – James Tan May 05 '21 at 07:31
  • `rm -rf node_modules` did not work for me but by executing the other two commands it fixed the errors! – Gass Aug 12 '22 at 10:53
15

It seems like you don't have react-scripts in your global environment. Two possibility are available here :

npm install -g react-scripts

or in your package.json change your script part like this :

  "scripts": {
    "start": "./node_modules/react-scripts/bin/react-scripts.js start",
    "start:prod": "pushstate-server build",
    "build": "./node_modules/react-scripts/bin/react-scripts.js build",
    "test": "./node_modules/react-scripts/bin/react-scripts.js test --env=jsdom",
    "eject": "./node_modules/react-scripts/bin/react-scripts.js eject",
    "server": "cd client/api && pm2 start server.js --watch",
    "proxy": "http://128.199.139.144:3000"
  },
Steeve Pitis
  • 4,283
  • 1
  • 21
  • 24
  • Now I got problem with index.html look like the create-react-app search in public dir ? But before I never get that. – EQuimper Oct 10 '16 at 14:24
  • 1
    take a look on the changelog ;) https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md#050-september-23-2016 – Steeve Pitis Oct 10 '16 at 14:28
  • 24
    This answer is wrong. This may fix the problem, but is not how Create React App is intended to be used. – Dan Abramov Oct 10 '16 at 14:42
9

Yes you should not install react-scripts globally, it will not work.

I think i didn't use the --save when i first created the project (on another machine), so for me this fixed the problem :

npm install --save react react-dom react-scripts
Chtioui Malek
  • 11,197
  • 1
  • 72
  • 69
9

incase you happened to be so unlucky like me that spent three(3) days in a row trying to solve this problem every solution proposed here failed me ... create a .env file in your project root and add this code SKIP_PREFLIGHT_CHECK=true. Good luck

Flavins
  • 123
  • 1
  • 5
6

This is to help others completely new to react and who area having problems just starting a first app even though they did a fresh install and try using npm install and the other fixes I saw around the forums.

Running it on Windows 10 with all the latest npm create-react-app installed and got failure after failure on a simple npm start in a simple my-app demo folder.

Spent a long time with what looks similar to the OP error at first but is slightly different. This starts with ERRNO 4058 and continues with code 'ENOENT' syscall: 'spawn cmd', path: ''cmd' ...

Eventually worked out from github create-react-app forum that a quick fix for this is registering cmd in the "path" variable. To do this go to System Properties>Environment variables. Click on path variable edit and and add new entry of C:\Windows\System32. Restart CMD prompt and I was good to go.

Tony_GR
  • 81
  • 1
  • 3
  • When all of my advanced fixes failed this was my problem. No idea how it got unset but this was the issue. – Raydot Apr 06 '20 at 17:59
  • being beginner myself, can you tell why we are adding windows system32 path. Means i could have better understood if we would have added node folder path. Can you pls explain ? – Yusuf Jun 08 '20 at 14:56
5

As Dan said correctly,

If you see this:

npm ERR! UpScore@0.6.0 start: `react-scripts start`
npm ERR! spawn ENOENT

It just means something went wrong when dependencies were installed the first time.

But I got something slightly different because running npm install -g npm@latest to update npm might sometimes leave you with this error:

npm ERR! code ETARGET
npm ERR! notarget No matching version found for npm@lates
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

so, instead of running npm install -g npm@latest, I suggest running the below steps:

 npm i -g npm //which will also update npm
 rm -rf node_modules/ && npm cache clean // to remove the existing modules and clean the cache.
 npm install //to re-install the project dependencies.

This should get you back on your feet.

antzshrek
  • 9,276
  • 5
  • 26
  • 43
5

I might be very late to answer this question but this is what has worked for me and it might help someone to get back on the development track!

nvm install v12.0 // You may need to install nvm, if not already done
rm -rd node_modules/
npm cache clean --force
npm install

Cheers!!

Learner
  • 157
  • 1
  • 7
2

For me it was simply that I hadn't added react-scripts to the project so:

npm i -S react-scripts

If this doesn't work, then rm node_modules as suggested by others

rm -r node_modules
npm i
Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
  • This has worked for me. I was getting the error on a fresh react project and apparently react-scripts were not installed automatically? – Nemo Nov 19 '19 at 19:48
2

I have faced the following issue.

enter image description here

Please find the solution:

  1. Add "C:\Windows\System32" to the global PATH environment variable.

  2. Check whether the environment variables has been created for nodejs,npm and composer. if not create one

enter image description here

  1. Run your app.
2

I had the same error when running

npm start

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! protest-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the protest-app@0.1.0 start script.

I broke my head on several tabs and applying Solutions from other devs and nothing.

Until, even using Ubuntu, I closed my vscode and restarted my pc and all my problems were solved. (kkkk zueira) just this one.

2

add environment variables in windows

  1. C:\WINDOWS\System32
  2. C:\Program Files\nodejs
  3. C:\Program Files\nodejs\node_modules\npm\bin
  4. C:\WINDOWS\System32\WindowsPowerShell\v1.0
  5. C:\Users{your system name without curly braces}\AppData\Roaming\npm

these 5 are must in path.

and use the latest version of node.js

Pramod Ukkali
  • 261
  • 2
  • 2
1

I solve this issue by running following command

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

hope it helps

Krishna Jangid
  • 4,961
  • 5
  • 27
  • 33
1

Add .env file with "SKIP_PREFLIGHT_CHECK=true" than npm start

Aakash Handa
  • 1,215
  • 11
  • 18
1

I fix this using this following command:

npm install -g react-scripts
Usama Majid
  • 1,103
  • 13
  • 13
1

it is simple but the first time it takes time a few steps to set !!!

  1. you have the latest version on node.

  2. go to the environment variable and set the path "%SystemRoot%\system32".

enter image description here

  1. run cmd as administrator mode.

  2. write command npm start.

HK boy
  • 1,398
  • 11
  • 17
  • 25
vikky singh
  • 356
  • 3
  • 6
1

i ran npm install inside the project then npm start it worked

F0cus
  • 585
  • 3
  • 18
  • 52
1

just delete the "node_module" file and if its seems somehow grey in folder that means it's not there just close the vs code and re open then

install npm with "npm install".

0

it's possible that conflict with other library, delete node_modules and again npm install.

0

This occurs when the node_modules gets out of sync with package.json.

Run the following at the root and any sub service /sub-folder that might have node_modules folder within it.

rd node_modules /S /Q
npm install
Chizl
  • 2,004
  • 17
  • 32
0

It occurred to me but none of the above worked.

events.js:72
        throw er; // Unhandled 'error' event
              ^

npm ERR! UpScore@0.6.0 start: `react-scripts start`
npm ERR! spawn ENOENT

Error: spawn ENOENT
    at errnoException (child_process.js:1000:11)
    at Process.ChildProcess._handle.onexit (child_process.js:791:34)

This happens because you might have installed react-scripts globally.

To make this work...

  1. Go to your C:\Users\<USER>\AppData\Roaming
  2. Delete npm and npm-cache directories... (don't worry you can install npm globally later)
  3. Go back to your application directory and remove node_modules folder
  4. Now enter npm install to install the dependencies (delete package-lock.json if its already created)
  5. Now run npm install --save react react-dom react-scripts
  6. Get it started with npm start

This should get you back on track... Happy Coding

Amirtha Rajan
  • 605
  • 10
  • 19
0

My issue was stemming from permission issues. I solved mine by following this https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

yoyoyoyo123
  • 2,362
  • 2
  • 22
  • 36
0

Type unset HOST in your terminal.

0

I have created react project locally. This reason of occurring this problem (for me) was that I didn't use sudo before npm and it needs root access (

> sudo npm start

PS1: For windows users, the powershell or command line should be run as administrator)

PS2: If use want to solve the root access issue, you can see this post.

Mostafa Ghadimi
  • 5,883
  • 8
  • 64
  • 102
0

for me I create a .env file in the project root and after that I write one line SKIP_PREFLIGHT_CHECK=true. It work for me