create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

`npm start` variable `BROWSER` is not working.

Open minnie-J opened this issue 3 years ago • 10 comments

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

minnie-J avatar Jan 02 '22 15:01 minnie-J

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)

daudminhas avatar Feb 05 '22 22:02 daudminhas

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.

tusharsdesai avatar Jun 13 '22 08:06 tusharsdesai

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


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

Remove the '--open'

ERGeorgiev avatar Jul 28 '22 12:07 ERGeorgiev

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

juan-montilla avatar Apr 20 '23 02:04 juan-montilla

bump

alexiuscrow avatar May 29 '23 10:05 alexiuscrow

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

shiva-karthick avatar Jun 19 '23 13:06 shiva-karthick

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.

yogeshwar-b avatar Oct 22 '23 18:10 yogeshwar-b

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.

elawad avatar Dec 02 '23 20:12 elawad