Reputation: 7474
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
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
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
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
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
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
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
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
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
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
Reputation: 51
delete node_modules
if above does't work
if above solutions does not fixed your problem, try the following this worked for me:
Upvotes: 3
Reputation: 69
Upvotes: 0
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
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
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
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
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
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).
run npm install
(or yarn
) to ensure all deps are downloaded.
If node_modules
exists, remove it with rm -rf node_modules
and then run npm install
(or yarn
).
Upvotes: 710
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
Reputation: 939
For me it was deleting package-lock.json
and node_modules
and then run npm install
again.
Upvotes: 1
Reputation:
I tried every answer but cleaning my npm cache worked..
steps:
Upvotes: 2
Reputation: 70
just run these commands
npm install
npm start
or
yarn start
Hope this will work for you thank you
Upvotes: 0
Reputation: 71
using npm i --legacy-peer-deps
worked for me.
I do not know specifically which operation out of the following it performed:
But I think it performs the latter operation. Feel free to let me know if I'm wrong ^-^
Upvotes: 7
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
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 :
npm install -g npm@latest
node_modules
directorynpm install
Upvotes: 25
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
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
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
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
Reputation: 332
this worked for me.
if you're using yarn:
yarn.lock
yarn
yarn start
if you're using npm:
package-lock.json
npm install
npm start
Upvotes: 2