Fixing 'react-scripts' is not recognized error

How to fix 'react-scripts' is not recognized as an internal or external command error

Posted on April 22, 2021

When running React applications with npm start or yarn start, you may encounter an error with react-scripts as follows:

'react-scripts' is not recognized as an internal or external command,
operable program or batch file.

Or just simply:

react-scripts: command not found
error Command failed with exit code 127.

Both errors occurred because your NPM or Yarn program can’t find the react-scripts module, which should be installed in your node_modules folder. The react-scripts package is supposed to be installed when you create a new React application using Create React App command-line tool.

To fix this kind of error, first check on your package.json file and see if react-scripts is listed as one of the dependencies in your project.

Here’s what you should see in your package.json file:

  "name": "my-react-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.0.1"
  // ... The rest is omitted

If the package is already listed, then try to re-install your dependencies with npm install or yarn command. The error should be fixed because react-scripts are now installed under node_modules folder.

If the error still appears, try to delete your node_modules folder first, then re-install your dependencies:

rm -rf node_modules/
npm install

On the other hand, if you don’t see react-scripts listed, then you need to install the package using your package manager:

npm install react-scripts
# or
yarn add react-scripts

That should add the package and you can try running the npm start command again.

If you still find the same error, there’s one last thing you can try to fix it, which is generating a new React application with Create React App.

First, create a new React App using the following command:

npx create-react-app my-react-app

Once the installation is finished, run the application using npm start command:

cd my-react-app
npm start

If your React application runs without any error, then copy your React project content (all the components and the dependencies) to this new React application and run your application from there.

If you still find the error, then your last option is to try to open a new issue at Create React App Github repository so that React team can help you out.

Related articles:

Level up your React skill today 🔥

Build FOUR projects using React with my latest book.

Structured knowledge from beginner to experienced level!

Learn more