4

i've just started out with react on codepen, and I really enjoy it! I decided to install it on my MacBook Air. I installed create-react-app using npm, and everything looked good. I then started a project, and everything went smoothly. When I ran npm start, I got an error:

sh: react-scripts: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! react-app@0.1.0 start: 'react-scripts start'
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the react-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I've come to the conclusion that npm can't find react-scripts. I have done almost everything I have come up with: I have updated npm; I have reinstalled the modules; I have started a new project, but I still get the same error. I've checked, react-scripts is in my node_modules file. The only thing I haven't done is install react-scripts globally, but the creator of create-react-app has said that that is a very bad idea. What should i do?

Emil E. Ohman
  • 153
  • 2
  • 11
  • Possible duplicate of [sh: react-scripts: command not found after running npm start](https://stackoverflow.com/questions/40546231/sh-react-scripts-command-not-found-after-running-npm-start) – Dmitriy Nov 24 '18 at 16:44

4 Answers4

5

Just solved the problem:

In package.json, I changed "start": react-scripts start", to "start": "NODE_ENV=production node_modules/react-scripts/bin/react-scripts.js start". This solved the problem.

Emil E. Ohman
  • 153
  • 2
  • 11
1

Try running npm install before running npm start, if that doesn't work check out this article on the same issue - sh: react-scripts: command not found after running npm start

Dmitriy
  • 1,211
  • 1
  • 11
  • 28
  • Have you tried all the steps in that post? Like rebooting your system and setting the NODE_ENV to development? – Dmitriy Nov 24 '18 at 17:00
1

Adding the entire path also worked for me: "start": "node_modules/react-scripts/bin/react-scripts.js start"

instead of just: "start": "react-scripts start".

I wish I knew why this behavior changed in my pc. Coincidence or not, I updated my xcode today.

Brydenr
  • 798
  • 1
  • 19
  • 30
Breno Oliveira
  • 139
  • 1
  • 5
0

delete package-lock.json: sudo rm package-lock.json

delete node_modules: sudo rm -rf node_modules

optionally upgrade npm: sudo npm install -g npm

and install project again npm i

run project: npm start

worked for me in the situation like you described