Skip to content

npm start variable BROWSER is not working.  #11873

Description

@minnie-J

package.json

"scripts": {
    "start": "BROWSER=chrome react-scripts start"
}

It works in CRA v4.x.
But it doesn't work in CRA v5.0.0
It opens with the default browser (Firefox).

Environment

Windows 10
WSL 2
node v14.16.0
npm v6.14.11

Activity

  1. daud-minhas commented on Feb 5, 2022

    @daud-minhas

    I also did a much research on this issue but couldn't find a working solution. The snippet below is not a proper solution but achieved my requirement and might be helpful for you.

    "start": "set \"BROWSER=none\" && start firefox localhost:3000 && react-scripts start" (Windows)

  2. tusharsdesai commented on Jun 13, 2022

    @tusharsdesai

    I tried setting the BROWSER envrionment variable on command line, in .env file, in package.json as well as exporting from my .bashrc (on Ubuntu), but it does not work with react-scripts 5.0.1. When I reverted back to 4.0.1, it worked. So something is still broken in 5.0.1.

  3. ERGeorgiev commented on Jul 28, 2022

    @ERGeorgiev

    IF YOU ARE USING ANGULAR:
    In the package.json:

    
      "scripts": {
        ....
        "start": "set \"BROWSER=none\" && ng serve --open",
        ....
      },
    

    Remove the '--open'

  4. juan-montilla commented on Apr 20, 2023

    @juan-montilla

    This issue is still happening.
    react-scripts: 5.0.1
    OS: Ubuntu

  5. alexiuscrow commented on May 29, 2023

    @alexiuscrow

    bump

  6. skrd-18 commented on Jun 19, 2023

    @skrd-18

    Yup, I am having the same issue too in WSL 2 Ubuntu

  7. yogeshwar-b commented on Oct 22, 2023

    @yogeshwar-b

    I can confirm, I still have this issue in WSL on Win 11. I tried having "BROWSER=chrome" in the scripts but that didn't help.

    Edit : Looks like my issue was different.

    I found the solution to my problem. I was running my project in the Windows file system (root/mnt/d/... here d is my local windows drive) from WSL, I moved my project to the Linux file system (root/home/..) and viola it started working fine.

  8. elawad commented on Dec 2, 2023

    @elawad

    Seeing this issue as well in CRA 5. But works in v4.

    On MacOS with Safari as default browser.
    Setting BROWSER=google chrome in .env no longer lunches Chrome, but Safari.

    Although if Chrome is already open, then CRA will use Chrome instead.
    This is not the case in v4; Chrome will always launch, even if was closed.

  9. Walker555 commented on Aug 14, 2024

    @Walker555

    This issue is still happening.
    react-scripts: 5.0.1
    OS: Linux-Mint

    I use Firefox as my default daily web browser and Chrome for development.

    workaround steps:

    1. disable start of OS default browser in package.json
    "scripts": {
        "start": "BROWSER=none react-scripts start"
    }
    
    1. use VS Code debugger launch.json config, for starting desired browser (Chrome):
    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "chrome",
                "request": "launch",
                "name": "Chrome localhost",
                "url": "http://localhost:3000",
                "webRoot": "${workspaceFolder}",
                "userDataDir": "${env:HOME}/.vscode/vscode-chrome-debug-userdatadir"
            }
        ]
    }
    
  10. elawad commented on Oct 9, 2024

    @elawad

    For anyone it may help, my recommendation is to move to Vite or RSBuild.

    We migrated a large CRA app to RSBuild.
    They even have a nice migration guide. https://rsbuild.dev/guide/migration/cra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions