78

I am currently trying to use create-react-app which uses three different packages: react, react-scripts and react-dom. I have installed create-react-app and then when I change into the directory and hit npm start I get a react-scripts: command not found. I've ran into a lot of problems with this. I can see react-scripts is in my node_modules folder but I keep getting command not found when trying to run npm start. I tried to delete and re-install all of my node_modules but it didn't work. Anyone else having this issue?

 ✘ ✝  Node/toDoApp/my-test   master±  npm start

> my-test@0.1.0 start /Users/jzilch/Desktop/Web 
Projects/Node:Express/Node/toDoApp/my-test
> react-scripts start

sh: react-scripts: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! my-test@0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the my-test@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely 
additional logging output above.
Bonifacio2
  • 3,405
  • 6
  • 34
  • 54
James Zilch
  • 1,055
  • 2
  • 10
  • 17
  • Create react app uses yarn. Did you try yarn start? – Joshua Underwood Dec 02 '17 at 21:15
  • 1
    Tried this with Yarn too and got the following after first trying to add with Yarn Globally `✝  Node/toDoApp/my-test   master±  yarn start yarn run v1.3.2 $ react-scripts start /bin/sh: react-scripts: command not found error Command failed with exit code 127. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.` – James Zilch Dec 02 '17 at 21:18
  • If you run npm install in the project directory. What happens? – Joshua Underwood Dec 02 '17 at 21:19
  • 1
    Everything installs but I do get an error on fsevents ` > fsevents@1.1.2 install /Users/jzilch/Desktop/Web Projects/Node:Express/Node/toDoApp/my-test/node_modules/fsevents > node install events.js:182 throw er; // Unhandled 'error' event ^ ` – James Zilch Dec 02 '17 at 21:22
  • My advice honestly would be to update node and create react app and then run through the process again. Preferably using sudo or admin depending on your OS – Joshua Underwood Dec 02 '17 at 21:24
  • 2
    Thanks. I tried to uninstall and re-install Node with Homebrew but still is not working. With yarn I do get more incite on what might be breaking. Yarn start return `/bin/sh: react-scripts: command not found` Leading me to believe that its trying to find this fine in /bin/sh: instead of node_modules. Not sure on this one as system files are not my forte – James Zilch Dec 02 '17 at 22:43
  • 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) – vsync Oct 06 '19 at 13:32

12 Answers12

84

Firstly Delete package-lock.json file in your project folder.

And then install dependencies again by npm install. That should solve this issue.

40

Delete the /node_modules directory and the package-lock.json file using the rm command:

rm -rf node_modules
rm -rf package-lock.json

Install react-scripts using the following command:

npm install react-scripts

Install the dependencies using the following command:

npm install

Start the local server by running the following command:

npm run start
venky royal
  • 1,860
  • 2
  • 11
  • 19
  • 4
    You are deleting `package.json` not `package-lock.json` with your command :) – Luca Perico Jan 25 '21 at 21:17
  • In case the edit doesn't go through, the last note is questionable. If you have to resort to `sudo` for `npm` commands, there's likely something wrong with the node installation. – General Grievance Mar 01 '23 at 19:37
30

This usually happens because of a bad npm packages installation (using npm and yarn at the same time?). It can be dispiriting, but if you try these steps, it should work.

1st solution:

Remove node_modules folder. At the project's root folder, run

> yarn
> yarn run start

2nd solution:

At the project's root folder, run

> yarn upgrade
> yarn
> yarn run start

Next time you want to add a dependency using create-react-app, I recommend you to use 'yarn add' instead of 'npm install'. (Source: https://github.com/facebook/create-react-app/issues/1155)

Will
  • 19,789
  • 10
  • 43
  • 45
Rocío García Luque
  • 3,597
  • 31
  • 31
10

I use this in a dockerizer enviroment. I already install locally in node_modules using package.json.

so, I added this:

RUN npm install -g react-scripts
RUN npm install

That solved my confusing issue

swdev
  • 4,997
  • 8
  • 64
  • 106
9

One option is to install the react-scripts package globally using the -g flag. This will make the command available to node, regardless of the working directory.

This command will install react-scripts globally:

npm install -g react-scripts
Dirk Diggler
  • 863
  • 1
  • 10
  • 22
Jamil Matheny
  • 180
  • 1
  • 7
7

As I was using yarn, I had to run yarn add react-scripts.

ignacio
  • 1,181
  • 2
  • 15
  • 28
5

I had this problem for ages and I eventually found my solution by sheer chance.
Turns out, you can't have spaces in any folder names.

e.g. ~/projects/tutorial/ReactJS/JavaScript Framework: ReactJS/app-name won't work because JavaScript Framework: ReactJS contains spaces.
In general, it's probably not great practice to be using spaces in folder/file names anyway but I hope this saves someone at least 4 hours of trial and error.

I would recommend removing the : from your folder names too! (just to be safe)

  • My issue was caused by me using `npx create-react-app app-name` inside of a folder named "npm/node" or `npm:node`. Using the command in a different directory named `npm-node` worked. – JJ Gerrish Jan 18 '20 at 17:00
  • In addition to this answer, an ampersand (&) can also cause this issue. This happened in my case. – Daniyal Malik Jun 18 '22 at 14:09
1

Delete your

  • node_modules
  • yarn.lock
  • manifest_lock.json
General Grievance
  • 4,555
  • 31
  • 31
  • 45
1

I fixed it by changing folder name in my local system, from

new/landing

to

new_landing

However, the git branch name remains like "new/landing". This was the case with my MAC system.

1

For me, I deleted the project and initialized another one with the npm create-react-app <Folder Name> script. Instead of create-react-app <Folder Name>. It worked for me.

0

$yarn $yarn run start

Running these commands two commands worked for me.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 18 '23 at 14:59
0

If anyone's having this issue with yarn, you can do

yarn global add react-scripts

and then delete your package-lock.json and node_modules folder.

Then, you can navigate to the main folder, and just do yarn and it will do a fresh install of your package.json dependencies.

KKM
  • 626
  • 5
  • 12