James Zilch
James Zilch

Reputation: 1225

react-scripts: command not found

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.

Upvotes: 94

Views: 206116

Answers (12)

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)

Upvotes: 32

KKM
KKM

Reputation: 744

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.

Upvotes: 0

Meghana Penmetsa
Meghana Penmetsa

Reputation: 1

$yarn $yarn run start

Running these commands two commands worked for me.

Upvotes: 0

user8219568
user8219568

Reputation:

Delete your

  • node_modules
  • yarn.lock
  • manifest_lock.json

Upvotes: 1

venky royal
venky royal

Reputation: 2250

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

Upvotes: 46

Oussama Jabrane
Oussama Jabrane

Reputation: 11

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.

Upvotes: 1

Jamil Matheny
Jamil Matheny

Reputation: 160

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

Upvotes: 9

ignacio
ignacio

Reputation: 1197

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

Upvotes: 7

MouseAndKeyboard
MouseAndKeyboard

Reputation: 445

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)

Upvotes: 5

Ved Prakash
Ved Prakash

Reputation: 121

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.

Upvotes: 1

swdev
swdev

Reputation: 5157

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

Upvotes: 10

user5395907
user5395907

Reputation:

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

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

Upvotes: 108

Related Questions