create-react-app: How do I “npm start” with a specific browser?

后端 未结 11 1944
一个人的身影
一个人的身影 2021-01-31 07:11

npm start

starts the react server on the default browser, which is Firefox for me. I like Firefox for browsing but prefer Chrome in web deve

相关标签:
11条回答
  • 2021-01-31 08:03

    To open in chrome we need to set it as a default browser.

    Setting --> Default browser --> Make default -->

    and choose chrome if any other browser is chosen.

    It worked on windows 10.

    0 讨论(0)
  • 2021-01-31 08:12

    Method by using .env file in the root of your NodeJS app.

    BROWSER="firefox developer edition"
    
    0 讨论(0)
  • 2021-01-31 08:12

    Using above technique, you may end up with error 'BROWSER' is not recognized as an internal or external command, operable program or batch file.

    To over come this Do an npm install of cross-env in your cloned repo: npm install --save cross-env

    Try to use this command in the package.json file

    "start": "cross-env BROWSER=chrome react-scripts start"

    BROWSER is an environment variable, and you can use the cross-env package to properly handle it.

    0 讨论(0)
  • 2021-01-31 08:15

    I don't like to repeatedly create a new .env file or prepend npm start every time with an additional command. You can specify your browser of choice instead of none in your shell config file. Type in your terminal the following commands:

    echo export BROWSER=none >> ~/.bashrc
    source ~/.bashrc
    

    At this point you can run npm start and be happy.

    0 讨论(0)
  • 2021-01-31 08:18

    If you are a Windows user then go to Sitting -> Default apps -> Web browser then select your desired browser.If you are a Linux user then go to System-settings -> Details. (Note: In older versions of Ubuntu Details is called System Info)

    0 讨论(0)
提交回复
热议问题