97

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

> [email protected] 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! [email protected] start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely 
additional logging output above.
7
  • Create react app uses yarn. Did you try yarn start? Commented Dec 2, 2017 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. Commented Dec 2, 2017 at 21:18
  • If you run npm install in the project directory. What happens? Commented Dec 2, 2017 at 21:19
  • 1
    Everything installs but I do get an error on fsevents ` > [email protected] 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 ^ ` Commented Dec 2, 2017 at 21:22
  • 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 Commented Dec 2, 2017 at 22:43

13 Answers 13

111

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

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

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

6 Comments

While deleting use "rm -rf"
package.json is not a directory so -rf should not really be necessary here.
package-lock.json is the file they're suggesting you delete, not package.json -- @Jim assuming this was just a typo, but want to save people some time if possible.
Why suggesting package-lock.json should be deleted?
@Siavoshkc package-lock.json ensures specific versions are installed when installing node modules. I assume the intention behind deleting it is to allow installation of a later version of whatever library may be causing this issue.
|
47

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

2 Comments

You are deleting package.json not package-lock.json with your command :)
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.
32

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.

NPM solution:

At the project's root folder, run:

> rm -rf node_modules
> rm -rf package-lock.json
> npm install

YARN solution:

At the project's root folder, run:

> rm -rf node_modules
> rm -rf yarn.lock
> yarn upgrade
> yarn

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)

Comments

11

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

Comments

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

Comments

7

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

Comments

6

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)

2 Comments

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.
In addition to this answer, an ampersand (&) can also cause this issue. This happened in my case.
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.

Comments

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.

Comments

1

Delete your

  • node_modules
  • yarn.lock
  • manifest_lock.json

Comments

0

$yarn $yarn run start

Running these commands two commands worked for me.

1 Comment

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.
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.

Comments

0

FWIW,

I had gone through re-installing everything, btw, you shouldn't use the -g option (I believe) because it installs globally and it can cause issues for React (at least for me). anyway after trying everything above it had to do with the react-scripts line in my package.json file.

Fix Update package.json

Edit your package.json and change this line:

"react-scripts": "^0.0.0"

to a particular version,

"react-scripts": "5.0.1"

Not entirely sure why because I would think the original value would install any available version.

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.