Devesh Jadon
Devesh Jadon

Reputation: 7474

sh: react-scripts: command not found after running npm start

I cloned a react application onto my system and ran following commands

npm install -g create-react-app
npm install --save react react-dom

After that i ran

npm start 

But it threw the above mentioned error, It is working fine on my other system from which i pushed it on github. But it is not working on any other system after cloning whether windows or mac.

Upvotes: 389

Views: 674174

Answers (30)

Musa Kazim
Musa Kazim

Reputation: 25

I tried removing node_modules and re-installing the dependencies but at the end this command helped me npm i react-scripts

Upvotes: 1

Austin
Austin

Reputation: 1

Try modifying your start script to use the appropriate command for your operating system. Here's how you can adjust it:

For Unix-based systems (Linux, macOS): export NODE_OPTIONS=--openssl-legacy-provider && react-scripts start

For Windows: SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts start

Upvotes: 0

stanley
stanley

Reputation: 11

In my case I moved the source code to the new folder, but "scripts" in package.json pointed to the previous location of node_modules

Upvotes: 0

Manish Gupta
Manish Gupta

Reputation: 1

Another reason I found for this issue:

The react runs the server at http://localhost:3000. If any server is already running at this port or this port is open in browser then command line throws sh: react-scripts: command not found error.

Upvotes: -1

Moti Bartov
Moti Bartov

Reputation: 3592

None of the above helped me..

For me there was something very strange.

The path of my project was something like this: /Downloads/package_name/project_name

From some reason, in the Download folder there was some left package.json file

I figured this out when I tried to run the script directly from project_name/node_modules/.bin/react-scripts build

The script failed and pointed this file as a problem

Once i deleted this orphaned package.json, it started to work.

I even then succeeded to reproduced this by creating empty package.json in the Downloads directory and the problem returned..

Upvotes: 0

DecafDevIO
DecafDevIO

Reputation: 11

My problem was that i'd renamed the folder to 'repo/project' which in CLI read as 'repo:project'. I don't think it liked that.

Upvotes: 0

PcodesDev
PcodesDev

Reputation: 36

For my case I had a package that was out of date and could not be install via npm. For my case the package was node-sass version 7.0.1 which is currently unavailable. I changed the package to version 9.0.0 in the package.json file and this solved the problem:

npm i [email protected]

Upvotes: 1

Kelijsto
Kelijsto

Reputation: 73

I resolved this issue with a global update of all dependency.

npm outdated | awk 'NR>1 {print $1"@"$4}' | xargs npm install

Upvotes: 0

Tammy
Tammy

Reputation: 11

Replace

"scripts": {
    "start": "../node_modules/.bin/react-scripts start",
    "build": "../node_modules/.bin/react-scripts build",
    "test": "../node_modules/.bin/react-scripts test",
   "eject": "../node_modules/.bin/react-scripts eject"
} 

with this

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
}

Upvotes: 1

Chanchala Gorale
Chanchala Gorale

Reputation: 161

Run npm i before you start the react project

Upvotes: 7

Manji
Manji

Reputation: 51

delete node_modules

  1. run npm install
  2. after that run npm start

if above does't work

  1. delete node_modules
  2. delete package-lock.json
  3. run npm install
  4. and then npm start

if above solutions does not fixed your problem, try the following this worked for me:

  1. if you want to start on another port or PORT command not found error then do the following steps:
    1. open package.json file
    2. inside script replace the start command with below "start": "set PORT=3006 && react-scripts start"
    3. To change the port of your app, you can also create a new file name .env in the root directory of the project and write in it PORT=3006 (then save the file). Now run your app using npm start.

Upvotes: 3

Tarun Tanmay
Tarun Tanmay

Reputation: 69

  1. delete package-lock.json file
  2. delete node_modules folder
  3. sudo npm i --force
  4. Enter your laptop login password (if asked)
  5. wait for node_modules to get installed
  6. npm start

Upvotes: 0

Nawal
Nawal

Reputation: 31

I was facing the same issue until I ran this piece of code in my Mac terminal:

sudo npm install -g yarn

Apparently, I was missing yarn on my machine.

Upvotes: 0

Alejandro Barrios
Alejandro Barrios

Reputation: 37

This workaround works for me

// in your package.json replace 
"start": "react-scripts start"

// with:
"start": "node_modules/react-scripts/bin/react-scripts.js start"

Upvotes: 2

Amer21
Amer21

Reputation: 51

After spending too much time trying all the solutions above, I can say for sure:

If you ran into this issue, check your path. If the path contains any special character or spaces just rename it and make sure that the new path doesn't have any spaces or special character. Then run it again .

Upvotes: 3

Riyad Zaigirdar
Riyad Zaigirdar

Reputation: 750

fixed it with

npm install --legacy-peer-deps

If you use npm to install and npm version is less than 7, then its npm most likey to behave in a smarter way. So, it will try to install react with its other depencies(peer deps)(higher versions if found), which will likely to break the library react. Attaching --legacy-peer-deps will tell npm "not to do something new", and install whats given in package.json...

Btw people seem to find yarn comfortable because this "not to install higher version if even found" is built in yarn automatically

reference: A referenced question

Upvotes: 0

Stephan Psaras
Stephan Psaras

Reputation: 87

None of these solutions worked for me. I found that the problem was the directory I was creating the project in, I am not sure why but when I created the project outside of that directory it worked. My solution was changing the directory to a new one from "React/Ionic" to "ionic-react". It could be that not only the project itself should be lowercase, but its parent folder as well, or it could be that the "/" in the directory name be the issue. Hope this helped.

Upvotes: 0

DeBraid
DeBraid

Reputation: 9441

Check if node_modules directory exists. After a fresh clone, there will very likely be no node_modules (since these are .gitignore'd).

Solution

run npm install (or yarn) to ensure all deps are downloaded.

Alternative Solution

If node_modules exists, remove it with rm -rf node_modules and then run npm install (or yarn).

Upvotes: 710

Ana Gabriele Soares
Ana Gabriele Soares

Reputation: 21

If you have tried everything and nothing solved it, try to rename the directories name. react will not start if the folder's name contains uppercase letters.

Upvotes: 2

David Lasry
David Lasry

Reputation: 939

For me it was deleting package-lock.json and node_modules and then run npm install again.

Upvotes: 1

user8453311
user8453311

Reputation:

I tried every answer but cleaning my npm cache worked..

steps:

  1. Clean cache =====> npm cache clean force.
  2. reinstall create-react-app =====> npm install create-react-app.
  3. npm install.
  4. npm start !!!

Upvotes: 2

Aditya Shinagari
Aditya Shinagari

Reputation: 70

just run these commands

npm install
npm start

or

yarn start

Hope this will work for you thank you

Upvotes: 0

MUdit TiWari
MUdit TiWari

Reputation: 71

using npm i --legacy-peer-deps worked for me.

I do not know specifically which operation out of the following it performed:

  • Installing the peer dependencies' latest stable version.
  • Installing the peer dependencies' version which the core dependy you are installing uses.

But I think it performs the latter operation. Feel free to let me know if I'm wrong ^-^

Upvotes: 7

shivam Agrawal
shivam Agrawal

Reputation: 9

If the above solutions don't work and you saw the below error:

npm ERR! The operation was rejected by your operating system.

npm ERR! It is likely you do not have the permissions to access this file as the current user

try with sudo npm install

Upvotes: 0

Chtioui Malek
Chtioui Malek

Reputation: 11525

you should not install react-scripts globally, for me this fixed the problem:

npm install --save react react-dom react-scripts

if this still dont work :

  1. update to latest npm version : npm install -g npm@latest
  2. delete node_modules directory
  3. reinstall all dependencies : npm install

Upvotes: 25

TOLULOPE ADETULA
TOLULOPE ADETULA

Reputation: 788

In package.json, I changed

"start": "react-scripts start"

to

"start": "NODE_ENV=production node_modules/react-scripts/bin/react-scripts.js start"

I hope this solves the problem for some people. Although the other solutions above seem not to work for me.

Upvotes: 27

Vanderley Maia
Vanderley Maia

Reputation: 485

You shoundt use neither SPACES neither some Special Caracters in you path, like for example using "&". I my case I was using this path: "D:\P&D\mern" and because of this "&" I lost 50 minutes trying to solve the problem! :/

Living and Learning!

Upvotes: 2

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 or wacky characters 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.

Also, any non-alphanumeric characters should be avoided.

Upvotes: 18

IanNoz
IanNoz

Reputation: 21

If anyone still have this problem after trying these solutions: check your project path as node has some issues working with spaced dir names. I changed all directories names that had spaces in their names and it worked perfectly.

solution idea taken from: https://npm.community/t/react-scripts-not-found/8574

i am using yarn BTW

Upvotes: 2

abdoo_salem
abdoo_salem

Reputation: 332

this worked for me.

if you're using yarn:

  1. delete yarn.lock
  2. run yarn
  3. and then yarn start

if you're using npm:

  1. delete package-lock.json
  2. run npm install
  3. and then npm start

Upvotes: 2

Related Questions