346

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.

Devesh Jadon
  • 7,004
  • 4
  • 22
  • 27

43 Answers43

651

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

DeBraid
  • 8,751
  • 5
  • 32
  • 43
  • 22
    This solution worked for me. But I also had to remove `package-lock.json`. – Victor Augusto Jul 14 '17 at 12:45
  • 14
    I also want to mention this happens **if the project is initialized using Yarn but then you attempt to run `npm install`**. This won't work: they're not compatible with each other. Running `npm install` on top of a Yarn-produced tree will corrupt it. I filed an issue [here](https://github.com/yarnpkg/yarn/issues/5240) but for now the solution is (if you use Yarn) to always use `yarn add` to add a package, and to delete `node_modules` and re-run `yarn` if you mess it up. – Dan Abramov Jan 17 '18 at 18:58
  • yes, it worked. But it seems like a common issue across the users. I would like to know what exactly causing the issue over here. – Arun Ramachandran Nov 09 '18 at 14:39
  • @ArunRamachandran cause of problem is in the first & second sentences: `After a fresh clone, there will very likely be no node_modules (since these are .gitignore'd).` – DeBraid Nov 09 '18 at 18:39
  • @DeBraid But I faced this problem after running 'npm install'. I cloned the repo, did npm install, later I had to add few more dependencies. The issue started after adding the additional dependencies. Is it overwriting something while installing the additional set of dependencies? – Arun Ramachandran Nov 11 '18 at 04:46
  • 1
    @ArunRamachandran the `package.json` file should not be overwritten when adding new deps with `npm install newDep`. Perhaps your project is using `yarn`? See https://stackoverflow.com/a/49575980/2700718 – DeBraid Nov 12 '18 at 15:52
  • 4
    It didn't work for me, I even tried deleting package-lock.json file – Kritish Bhattarai Jun 11 '20 at 09:49
  • `npm install --force` worked for me (after trying none of these answers work...) – nambk Mar 22 '21 at 17:35
75

Tried all of the above and nothing worked so I used npm i react-scripts and it worked

Pip
  • 1,062
  • 8
  • 6
39

I had similar issue. In my case it helped to have Yarn installed and first execute the command

yarn

and then execute the command

yarn start

That could work for you too if the project that you cloned have the yarn.lock file. Hope it helps!

user158
  • 12,852
  • 7
  • 62
  • 94
Fabio Nolasco
  • 7,122
  • 6
  • 35
  • 32
  • 4
    Does anyone know WHY using `yarn` fixes an `npm` problem? – DJ2 Jun 18 '19 at 17:33
  • In my case, `yarn start` was not working as the dedicated port (8081) was reserved by previously running process. I had to kill it `kill -9 $(lsof -t -i:8081 -sTCP:LISTEN) ` and run `yarn start` – KeshavDulal Sep 24 '20 at 04:35
25

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.

LinusGeffarth
  • 27,197
  • 29
  • 120
  • 174
TOLULOPE ADETULA
  • 768
  • 1
  • 12
  • 27
23

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
LinusGeffarth
  • 27,197
  • 29
  • 120
  • 174
Chtioui Malek
  • 11,197
  • 1
  • 72
  • 69
16

https://github.com/facebookincubator/create-react-app

npm install -g create-react-app

create-react-app my-app
cd my-app/
npm start

You install the create-react-app package globally. After that you run it and create a project called my-app. Enter your project folder and then run npm start. If that doesn't work try running npm install and then npm start. If that doesn't work as well, try updating your node version and/or npm.

Dan Andersson
  • 337
  • 1
  • 6
16

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.

10

This error occurs when you Install package with npm install instead of yarn install or vice-versa.

dealwap
  • 621
  • 2
  • 14
  • 33
7

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

MUdit TiWari
  • 71
  • 1
  • 2
5
npm install --save react react-dom react-scripts

Above command worked for me.

Krupal Patel
  • 512
  • 8
  • 12
5

Run npm i before you start the react project

4

This boggles me time to time when I have a fresh start with create-react-app, please make sure your NODE_ENV variable is set to development not production, as devDependencies in your package.json will not be installed by npm install.

sed
  • 5,431
  • 2
  • 24
  • 23
4

If you are having this issue in a Docker container just make sure that node_modules are not added in the .dockerignore file.

I had the same issue sh1 : react scripts not found. For me this was the solution

arslaanmalik
  • 55
  • 1
  • 1
  • 8
3

Just ran into this problem after installing material-ui.

Solved it by simply running npm install again.

mikeym
  • 5,705
  • 8
  • 42
  • 62
3

Just doing an Yarn install solved the problem for me

kartick shaw
  • 915
  • 13
  • 5
2

Deleting package-lock.json and node_modules then npm install worked for me.

wigg
  • 21
  • 1
2

If none of the other answers work properly (after updating the npm etc). I would strongly recommend you to install the project on your desktop.

create-react-app project_name

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Ferdin
  • 21
  • 2
2

The solution that worked for me is below. Try creating React app with this command.

create-react-app react-app --scripts-version 1.1.5
coderpc
  • 4,119
  • 6
  • 51
  • 93
2

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
abdoo_salem
  • 312
  • 3
  • 9
2

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

IanNoz
  • 21
  • 2
2

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!

Vanderley Maia
  • 465
  • 5
  • 7
2

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.

2

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 .

SamiElk
  • 2,272
  • 7
  • 20
Amer21
  • 21
  • 2
  • This seems rather vague. The `PATH` is not particularly sensitive to what characters your directory names contain, other than of course if a directory contains a literal `:` which is the `PATH` delimiter (but on a Mac, you can't really have colons in file names anyway IIRC). Naturally, you need to make sure that you have not misspelled the directories in your `PATH` (including but not limited to ensuring that your shell's strartup files don't contain DOS carriage returns, which could happen if you edit them on Windows; see also https://stackoverflow.com/questions/39527571/) – tripleee Dec 17 '22 at 11:02
2

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"
2

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.
Manji
  • 31
  • 5
1

I just randomly experienced this "react-scripts: command not found" error after issuing a react-scripts build request, which was previously working just fine.

A simple reboot of my system corrected the issue.

Ben Thielker
  • 4,104
  • 4
  • 21
  • 20
1

if anyone is willing to use npm only, then run this npm i react-native-scripts --save, then npm start or whatever the command you use

1

solution 1:

delete the package-lock.json file and then type -> npm install

solution 2:

/Users/piyushbajpai/.npm/_logs/2019-03-11T11_53_27_970Z-debug.log

like this is my debug path --> so this you will find in the console -> press on command and click on the link, you will find error line; like this:

verbose stack Error: nest_form@0.1.0 start: react-scripts start

solution 3:

delete the node_module and npm i with fresh way.

solution 4:

go to node_module and delete jses folder and delete it, then do npm i and again start with npm start

Skandix
  • 1,916
  • 6
  • 27
  • 36
1

I had issues with latest version of yarn 1.15.1-1

I've fixed it by downgrading to lower version sudo apt-get install yarn=1.12.3-1

Amir Katz
  • 1,027
  • 1
  • 10
  • 24
1

I ran into this error after renaming the directory with the @/ symbol on macOS to match the name of my NPM package namespace.

When the NPM command looked for installed packages in my local node_modules, it couldn't find it due to the way macOS was rewriting the directory path. After renaming the directory without @/ I was up and running again.

chrisjsherm
  • 1,269
  • 13
  • 17
1

Just You have to restore packages to solve this issue, So just run command :

npm install or yarn install

niks
  • 426
  • 4
  • 9
1

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 !!!
1

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

David Lasry
  • 829
  • 3
  • 12
  • 31
1

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"
}
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Tammy
  • 11
  • 1
0

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

0

just run these commands

npm install
npm start

or

yarn start

Hope this will work for you thank you

Yehor Androsov
  • 4,885
  • 2
  • 23
  • 40
0

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.

0

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

Riyad Zaigirdar
  • 691
  • 3
  • 8
  • 22
0

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.

Nawal
  • 31
  • 1
  • 6
0
  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
0

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

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

Kelijsto
  • 73
  • 7
0

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 node-sass@9.0.0
PcodesDev
  • 1
  • 1
  • 3
0

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.