Debug School

rakesh kumar
rakesh kumar

Posted on

React Error:'PORT' is not recognized as an internal or external command, operable program or batch file.

Error

client@0.1.0 start
PORT=3006 react-scripts start

'PORT' is not recognized as an internal or external command,
operable program or batch file. when i npm start at client side

Solution

The error message you are encountering indicates that the 'PORT' environment variable is not being recognized when you run the npm start command on the client side of your application. This issue is likely related to the way you are setting the 'PORT' environment variable.

In the command you provided:

PORT=3006 react-scripts start
Enter fullscreen mode Exit fullscreen mode

It appears that you are trying to set the 'PORT' environment variable to the value 3006 and then start the React application using react-scripts. However, the syntax used here may not work on all operating systems or shells.

To fix this issue, you can try the following steps:

  1. Use cross-platform syntax for setting environment variables:

On Windows, use the set command:

set "PORT=3006" && react-scripts start
Enter fullscreen mode Exit fullscreen mode

On macOS or Linux, use the export command:

export PORT=3006 && react-scripts start
Enter fullscreen mode Exit fullscreen mode

2. Use a different method to set the 'PORT' variable:

If the above approach doesn't work, you can try using a different method to set the 'PORT' environment variable. For example, you can use a .env file in the root directory of your React application:

Create a .env file and add the following line:

PORT=3006
Enter fullscreen mode Exit fullscreen mode

Then, modify your start script in the package.json file of the client-side like this:

"scripts": {
  "start": "react-scripts start"
}
Enter fullscreen mode Exit fullscreen mode

With this setup, the 'PORT' environment variable will be automatically read from the .env file when you run npm start.

Remember that the method for setting environment variables can vary depending on your operating system and shell. By following one of these approaches, you should be able to resolve the 'PORT' not recognized error and start your React application successfully.

Top comments (0)