If you are confused and don’t know how to fix the error “sh: react-scripts: command not found”, let’s follow this article. We will give you some solutions to fix it.
The reason for the error “sh: react-scripts: command not found”
Not have ‘node-module‘
The most common reason for this error is that you forgot to install React initially so you don’t have a node module providing your command:
npx create-react-app my-app
Then you can get something like this:
Solutions to fix this error
Run the command
So you can run the command to start your project:
cd my-app
npm start
Or you can get error went lost ‘node_module’ file.
Example:
If my folder does not exist, I will get the error.
To solve this error, you should run this command below:
npm i
npm start
If you are using yarn, use this:
yarn
yarn start
If you want to re-install node_modules, you can remove the folder by this command:
rm –rf node_modules
-rf
here stands for remove file. After removing file you can re-install it by command:
npm i
or
yarn
Change package.json
In package.json file, we will see this code line:
{ // Some code line... "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, // Some code line... }
Here in the start scripts you should change it to:
“start”: “NODE_ENV=production node_modules/react-scripts/bin/react-scripts.js start”
Example:
{ // Some code line... "scripts": { "start": "NODE_ENV=production node_modules/react-scripts/bin/react-scripts.js start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, // Some code line... }
You will set your NODE_ENV to run manually instead of running auto by default.
Install ‘react-scripts‘
You can also get the error if you do not install ‘react-scripts’ globally. So to install ‘react-scripts‘ global, use this command:
npm i --save react react-dom react-scripts
Remove spaces in the path to project
If the path to your project has spaces, it will get an error.
Example:
This will get to the error.
user/my_project/my first project
This will work
user/my_project/my_first_project
You can always make a mistake when trying to pass the path to your project. So make sure you pass in the correct path.
Summary
In this tutorial, I’ve shown you how to solve the error “sh: react-scripts: command not found”. You can re-install your ‘node_module’, or you can set the way you start your React app. I hope these solutions can help you.
Maybe you are interested:
- error “ReactDOM.render is no longer supported in React 18. Use createRoot instead”
- React refers to UMD global, but the current file is a module
- React Native build error: Undefined symbols for architecture x86_64
Hello, guys! I hope that my knowledge in HTML, CSS, JavaScript, TypeScript, NodeJS, ReactJS, MongoDB, Python, MySQL, and npm computer languages may be of use to you. I’m Brent Johnson, a software developer.
Name of the university: HOU
Major: IT
Programming Languages: HTML, CSS, JavaScript, TypeScript, NodeJS, ReactJS, MongoDB, PyThon, MySQL, npm