'react-scripts' is not recognized as an internal or external command

The error: 'react-scripts' is not recognized as an internal or external command is occur when npm can’t find the react-scripts module, which should be installed in your node_modules folder by default when you create a react project using create-react-app.

To fix this error follow the below steps:

Step 1: Check package.json file.

Open the package.json file in the root directory and check whether react-scripts is listed under dependencies or not. A sample package.json file is given below.

{
  "name": "reactdi",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  ...
  ...
  ... 
}

If react-scripts is present in package.json

If react-scripts is already present in the file, then try to reinstall the dependencies by the below command.

npm install

If react-scripts is not listed in package.json

If react-scripts is not listed in the file, then install the package using the below command.

# npm command
npm install react-scripts

# yarn command
yarn add react-scripts

After installing, you can run react application using npm start command.

If again the error exists, then follow the below steps.

Step 2: Delete node_modules and reinstall dependencies

If the issue still exists, delete the node_modules folder from the root directory of the react project.

Then clear the npm cache by running the below command.

# npm command
npm cache clean --force

# yarn command
yarn cache clean

Next, reinstall the dependencies using the below command.

# npm command
npm install

# yarn command
yarn install

Step 3: Run the command npm audit fix

If the issue still exists after doing steps 1 and 2, then run the below command.

npm audit fix

The npm audit fix subcommand will automatically install compatible updates to vulnerable dependencies.

If all the above steps not worked for you, go for re-installing node.js.

Conclusion

To solve the error: 'react-scripts' is not recognized as an internal or external command”, make sure react-scripts npm package was installed in the project. If already been installed and the issue still exists, then delete the node_modules folder, clear npm cache and reinstall the dependencies.