[Fixed] How to Fix “‘BROWSER’ is not recognized as an internal or external command” Error – Javascript

Photo of author
Written By M Ibrahim
d3.js javascript reactjs
Quick Fix: Install the cross-env package and modify the dev script in the package.json file to include “cross-env BROWSER=none” before the existing command.

The Problem:

When trying to run a React app locally using the command "npm run dev", the error message "’BROWSER’ is not recognized as an internal or external command, operable program or batch file" is displayed. This error prevents the app from running successfully.

The Solution:

Solution 1: Install cross-env

To fix this issue, install the cross-env package by running the following command in the cloned repository:
npm install --save cross-env

Then, open the package.json file in the cloned repository and modify the dev script as follows:
"dev": "cross-env BROWSER=none yarn clean:lib && webpack --progress --colors --watch --env dev"

Solution 2: Use concurrently and wait-on

Another solution is to use the concurrently and wait-on packages. Install them by running the following command:
npm install concurrently wait-on

Then, modify the dev script in the package.json file as follows:
"electron-dev": "concurrently \"cross-env BROWSER=none yarn start\" \"wait-on http://localhost:3000 && electron .\""

Solution 3: Set the BROWSER environment variable

You can also set the BROWSER environment variable manually. Open the command prompt and run the following command:
set BROWSER=none

Now, try running the app again using the command "npm run dev". The error should no longer occur.

Conclusion:

The "’BROWSER’ is not recognized as an internal or external command" error can be resolved by installing the cross-env package, using concurrently and wait-on packages, or setting the BROWSER environment variable. By following these solutions, you can successfully run your React app locally without encountering this error.

Sources: