DEV Community

Coder
Coder

Posted on

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

So, you're trying to start a new React application, but you get an error saying 'react-scripts' is not recognized as an internal or external command, operable program or batch file. This error can be frustrating, especially if you're new to React development. Fear not, though, as we've got you covered with a comprehensive solution guide.

What is react-scripts?

Before we dive into the solution guide, let's first establish what react-scripts is. react-scripts is a set of scripts and configuration used by Create React App (CRA) to manage the development environment and build process of your React application. CRA is a popular tool used by developers to bootstrap React projects, which makes it easy to get started with React development.

react-scripts includes preconfigured tools such as Webpack, Babel, and a development server, so you don't have to worry about configuring them manually. It also includes scripts for running and building your application in development and production environments.

Why am I seeing the error message 'react-scripts' is not recognized as an internal or external command, operable program or batch file.?

The error message occurs because your computer cannot find react-scripts when trying to execute the command. This could be due to a few reasons such as:

  • create-react-app not being installed globally on your computer.
  • node_modules folder not being present in your project directory.
  • A problem with your system's environment variables.

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

Let's go through each of the possible solutions step by step.

Solution 1: Install create-react-app globally

The first thing to check is whether you have create-react-app installed globally on your computer. This will ensure that you have the latest version of create-react-app installed, and it will also ensure that you have access to react-scripts.

Step 1: Open up your terminal or command prompt.

Step 2: Run the following command to install create-react-app globally:

npm install create-react-app -g
Enter fullscreen mode Exit fullscreen mode

This command installs create-react-app globally on your computer, which means you can now use it to create new React applications from anywhere on your system.

Step 3: Once create-react-app has been installed globally, navigate to your project directory using the cd command.

Step 4: Run the following command to create a new React application:

create-react-app my-app
Enter fullscreen mode Exit fullscreen mode

This command will create a new React application called my-app in your current directory.

Solution 2: Check that node_modules exists

Another reason you might see this error is that the node_modules folder is not present in your project directory. node_modules is a folder that contains all the dependencies installed by npm when you run npm install in your project directory.

Step 1: Open up your terminal or command prompt.

Step 2: Navigate to your project directory using the cd command.

Step 3: Run the following command to check if node_modules exists in your project directory:

ls node_modules
Enter fullscreen mode Exit fullscreen mode

If you see an error message that says ls: cannot access 'node_modules': No such file or directory, it means that the node_modules folder is not present in your project directory.

Step 4: To install the required dependencies, run the following command:

npm install
Enter fullscreen mode Exit fullscreen mode

This command will install the required dependencies, including react-scripts, in your project directory.

Step 5: Once the installation process is complete, run the following command to start your React application in development mode:

npm start
Enter fullscreen mode Exit fullscreen mode

Solution 3: Check your system's environment variables

The last possible cause of 'react-scripts' is not recognized as an internal or external command, operable program or batch file. error message is a problem with your system's environment variables. Environment variables are values set by your operating system that applications can use to locate required resources.

Step 1: Open up your terminal or command prompt.

Step 2: Run the following command to check your system's environment variables:

echo %PATH%
Enter fullscreen mode Exit fullscreen mode

This command will display the values of your system's environment variables.

Step 3: Look for the directory containing the node_modules folder. If it is not included in the PATH environment variable, that might be the cause of the issue.

Step 4: To add the node_modules directory to the PATH environment variable, follow these steps:

  • Right-click on "Computer" (or "This PC") in the file browser and select "Properties".
  • Click on the "Advanced system settings" link.
  • Click on the "Environment Variables" button.
  • Under "System variables", scroll down and find the "Path" variable. Click on the "Edit" button.
  • Click on the "New" button and add the path to the node_modules directory (e.g. C:\Users\JohnDoe\my-project\node_modules) to the list of values.
  • Click on "OK" to save the changes.

Step 5: Restart your command prompt or terminal and navigate to your project directory.

Step 6: Run the following command to start your React application in development mode:

npm start
Enter fullscreen mode Exit fullscreen mode

Conclusion

In conclusion, 'react-scripts' is not recognized as an internal or external command, operable program or batch file. error message can be frustrating, but it is usually due to a simple problem that can be solved easily. With the comprehensive solution guide above, you should now be able to fix this issue and get back to developing your React applications without any problems.

Top comments (0)