Categories
JavaScript Answers

How to run “npm start” with a specific browser with create-react-app?

Spread the love

To run "npm start" with a specific browser with create-react-app, we set the BROWSER environment variable.

For instance, in package.json, we write

{
  //...
  "scripts": {
    "start": "BROWSER='chrome' react-scripts start"
  }
  //...
}

to set the BROWSER environment variable to 'chrome'.

And then we run react-scripts start to start create-react-app with Chrome.

This works on windows.

On Linux, we write

{
  //...
  "scripts": {
    "start": "BROWSER='google-chrome-stable' react-scripts start"
  }
  //...
}

And on Mac OS, we write

{
  //...
  "scripts": {
    "start": "BROWSER='google chrome' react-scripts start"
  }
  //...
}

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *