182

I've created a React app using create-react-app but whenever I start the dev server (using npm start), it opens up my browser. I want to make it so that it doesn't open my browser whenever I start my dev server.

How can I accomplish this?

5 Answers 5

301

Create .env file in the root directory where your package.json file resides. And add the following:

BROWSER=none

Now run npm start.

Sign up to request clarification or add additional context in comments.

7 Comments

Is this documented anywhere? It seems 'react-scripts' has no documentation at all.
It seems sometimes react-scripts misses the .env file, so in your package.json, you can add "start": ". ./.env; react-scripts start"
@JeffreyDrake It's documented here.
If you are using Windows go to packaga.json file and right after "scripts": { replace "start": "react-scripts start", with "start": "env BROWSER=none react-scripts start",
@BushraMustofa Does not work on windows for me ('env' is not recognized as an internal or external command, operable program or batch file.). The .env file based approach works for me on Windows.
|
111

Add BROWSER=none to your npm start script in your package.json file, like this:

"scripts": {
  "start": "BROWSER=none react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test",
  "eject": "react-scripts eject"
},

Check out the CRA documentation for more configuration and environment variable options:

https://create-react-app.dev/docs/advanced-configuration/


Update/Troubleshooting:

In case you're having a 'BROWSER' is not recognized as an internal or external command, operable program or batch file error: do an npm install of cross-env:

npm install --save cross-env

Then, add cross-env BROWSER=none to your start script

"start": "cross-env BROWSER=none react-scripts start",

1 Comment

If you don't want to install cross-env globally, just add cross-env to your devDependencies and use "start": "npx cross-env Browser=..."
25

For Windows you can edit/create a script in package.json like this one. There must be no blank before the &&:

"start": "set BROWSER=none&& react-scripts start"

For Linux based OS, just delete the "set" and the "&&" and it will work:

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

4 Comments

You can use cross-env to have the same way of defining these scripts
doesnt work for me. no error, it simply ignores the set BROWSER=none on windows for me
fixed the answer. there must be no blank before &&. no idea why
Thanks, for suggesting the set BROWSER=none part, I wasted 1 hr search for a way to fix "cannot find BROWSER command"
10

I suggest doing it at the command level, so you don't have to change any files that get committed.

BROWSER=none npm start

You can add an alias for this to your shell's configuration:

alias myapp-start='cd /path/to/myapp && BROWSER=none npm start'

Comments

2

If you have InteliJ IDEA you can also on the top right menu click your npm start and Edit Configurations, then in the Environment write:

BROWSER=none

Of course it will be right there only if you clicked on it in package.json at least once.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.