React port is not recognized as an internal or external command, operable program or batch file.

React port is not recognized as an internal or external command, operable program or batch file.

React logo

If you’re using Windows to develop react apps, you might come across this error in Command Prompt (cmd.exe):

‘create-react-app’ is not recognized as an internal or external command

Or in PowerShell (powershell.exe):

create-react-app: The term ‘create-react-app’ is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

This, of course, means create-react-app cannot be found. This can be caused by a few things:

  • create-react-app is not installed
  • The npm folder does not exist environmental PATH variable
  • Something is wrong with npm

Let’s go in order to ensure everything is set up as expected.

Do npm and npx work?

In Command Prompt or PowerShell, type:

npm and press enter
npx and press enter

Do both commands work? If one or both commands do not work, I recommend installing nvm (Node version manager), which makes installing and switching between NodeJS versions easy. See this site for instructions.

Is create-react-app actually installed?

Make sure create-react-app is installed.

In Command Prompt or PowerShell, type:

npm install --global create-react-app

Once it’s installed, type create-react-app and press enter.

If it’s still broken, there’s probably only one reason it’s not working: missing folder in the PATH variable

Fix PATH environment variable

If everything is correct so far, then the problem is most likely a problem with the PATH variable. Not a hard fix, don’t worry.

The PATH variable is an environmental variable that contains a list of folders that Windows uses to access a file from any directory. So if the PATH variable contains C:\Windows\System32 and you’re in another directory such as C:\Users, typing calc.exe will launch Calculator as if you were in the C:\Windows\System32 directory (since calc.exe is actually located in C:\Windows\System32).

Applying this to NodeJS, the PATH variable must contain the folder where the NodeJS the .cmd files reside that call the scripts such as create-react-app:

Open PowerShell as Administrator (not Command Prompt) and type:

explorer (npm — global root)\.. and press enter

That should take you to a folder that contains:

  • node.exe
  • npm.cmd
  • create-react-app.cmd

and a few other files.

If you don’t see these files, you need to reinstall NodeJS.

If you do see these files, good! Now we just need to add this folder to the PATH variable.

  • Press Win+R and type sysdm.cpl and press enter
  • Click the Advanced tab and click Environment Variables at the bottom
  • In the bottom section where it says System variables, find the Path variable and double-click it
  • Click New and then type the name of the folder that opened in the previous step
  • Note that my path is C:\Program Files\nodejs but yours may be different (such as in AppData), that’s okay!

React port is not recognized as an internal or external command, operable program or batch file.

  • Make sure to click Move Up until it’s at the very top of the list
  • Click OK when done
  • Restart your computer (required in order to reload the system environment variables)

That should take care of it! Have fun coding! 😊

Posted on Apr 22, 2021

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

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.

How do you fix react

To solve the error "react-scripts is not recognized as an internal or external command, operable program or batch file", open your terminal in your project's root directory and install the react-scripts package by running npm install react-scripts and clear your npm cache if necessary.

How do you fix create

Use npx to solve the error "create-react-app is not recognized as an internal or external command, operable program or batch file", e.g. npx create-react-app my-app or install the package globally by running npm install -g create-react-app . The fastest way to solve the error is to use the npx command.

How do I open react app in specific PORT?

To change the default port for a create-react-app project, update the start command in your package. json file to specify the port, e.g. "PORT=3456 react-scripts start" on macOS and Linux and "set PORT=3456 && react-scripts start" on Windows.

How do I set a react port number?

In ReactJS, the easiest way to alter the port number is by setting an environment variable named PORT to the desired number via the terminal. As an example, here we change the port number to 5000. your local server will run on port 5000.