Stop Create-React-App from opening the browser on npm start

Stop Create-React-App from opening the browser on npm start

Create-React-App, by default, will launch your application in your default browser or Google Chrome when no default browser is set.

Although, this is the default behavior for Create-React-App, you might want to disable this behavior for some reasons best known to you.

To do that, we fortunately don't need to install any third party library as Create-React-App has a built-in method of controlling this. You can easily override the default behavior with your own by specifying a specific browser or none.

You can do this in two ways:

1. Environment Variable

You can adjust this configuration by setting an environment variable which would look like:


Where name_of_browser could be firefox, google-chrome, or none. You don't need to prefix the variable name with REACTAPP as you normally do for your environment variables.

Also, you need to note that the browser name is not universally the same across all Operating Systems. For example, BROWSER=google-chrome will work on both MacOS and Linux but not on Windows. For Windows, use BROWSER=chrome instead. That's something you need to watch out for.

2. The package.json file

The other method is for you to specify the BROWSER in the package.json file. Specifically, in the scripts.

"scripts": {
    "start": "BROWSER=none react-scripts start",

When next you start your application with npm start, your application won't open in any of the browsers.

I hope this was helpful in your react-ful journey.

Thanks for reading and...happy coding!