5

I have a react project that I am running using npm. When I do npm start, it launches on my default browser:- google chrome.

I would like to launch on firefox, safari and internet explorer for manual testing. I prefer don't making changes to package.json due to one time use.Any ideas on how to go about?

Specs

node -p process.arch: x64

node -p process.platform: darwin

npm info react version 16.4.0

macOS 10.13.4 (17E199)

2
  • Can you post what your package.json looks like? Commented Jun 4, 2018 at 18:53
  • try update packages: npm update Commented Oct 25, 2018 at 9:29

4 Answers 4

10

Create an environment file .env at the root of the project directory and add following entry

BROWSER=firefox

For a complete list of .env file configuration, you can check here - https://facebook.github.io/create-react-app/docs/advanced-configuration

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

Comments

3

As I read on the script that runs when you run npm start, you may set an environment variable called BROWSER before running the npm start

For example (on linux):

(export BROWSER=firefox;  npm start)

also, you may open the browsers after starting:

npm start &
firefox http://localhost:3000
safari http://localhost:3000

Save it to a something.sh and run this shell script. If you are on windows, you may do something similar on .bat script

Comments

2

you can install global node package called opn-cli then you can run the command. https://www.npmjs.com/package/opn-cli

Sample command:

npm start & opn http://localhost:4200 -- firefox & opn http://localhost:4200 -- chrome

Comments

0

First Install This:-

npm install --save cross-env

Than and update package.json file scripts only :-

Old

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

},

Update

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

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.