4

I just started a project with react-create-app template typescript.

When I do npm run dev it opens edge browser, I was expecting chrome.

Any idea how to make it open in chrome?

angry kiwi
  • 10,730
  • 26
  • 115
  • 161
  • Does this answer your question? [create-react-app: How do I "npm start" with a specific browser?](https://stackoverflow.com/questions/51706882/create-react-app-how-do-i-npm-start-with-a-specific-browser) – Emile Bergeron Feb 15 '21 at 20:30

7 Answers7

5

From Create React App documentation

By default, Create React App will open the default system browser, favoring Chrome on macOS. Specify a browser to override this behavior, or set it to none to disable it completely. If you need to customize the way the browser is launched, you can specify a node script instead. Any arguments passed to npm start will also be passed to this script, and the url where your app is served will be the last argument. Your script's file name must have the .js extension.

Easy answer is to change your default browser. However if you want to keep your default browser to Edge you can do this.

BROWSER=chrome npm start
BROWSER=chrome npm run dev

Consider that browser names are different. For example, Chrome is google chrome on macOS, google-chrome on Linux and chrome on Windows.

Linux
"start": "BROWSER='google-chrome-stable' react-scripts start"
Windows
"start": "BROWSER='chrome' react-scripts start"
Mac
"start": "BROWSER='google chrome' react-scripts start"
sadrzadehsina
  • 1,331
  • 13
  • 26
  • This helped me. But I'll make an amendment. I had to do this: (in Win10) "start": "set BROWSER='chrome'; react-scripts start" I use FireFox for most of my web projects. However, in this instance I need Chrome. So, I can't just change the default at the OS/IDE level. – lerenau Sep 18 '21 at 23:38
0

Likely it opens in your default browser, this is an OS setting.

0

This question might probably gives the answer: create-react-app: How do I "npm start" with a specific browser?

In short: "By default, Create React App will open the default system browser, favoring Chrome on macOS." from the documentation. My guess is that your default browser is set to Edge, and if you set it to Chrome, it will open it in Chrome instead.

Barnabas Ujvari
  • 399
  • 3
  • 5
0

(Windows) It may very well be a default web browser situation in which you'll need to do a search for Default apps --> click on the current browser under Web browser --> select preferred browser.

Remiiiiii
  • 11
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 27 '23 at 08:25
0

I made the mistake of installing Microsoft Edge on my Mac. I didn't set it to the default web browser and verified that Chrome is the default.

However, ever since then, when I run npm start, the development server insists on trying to launch the app in Edge. Even after deleting Edge, it prompts: "Choose Application - Where is Microsoft Edge?"

So I simply chose Google Chrome at that prompt, which I tried to avoid but couldn't quickly find an alternative.

msun
  • 761
  • 4
  • 8
0

The other answers aren't quite correct. VSCode's choice of which browser to open is a bit ... idiosyncratic. Chrome is used by default (if it's installed) on MacOS, regardless of whether it's the OS's default browser. I don't have a Windows machine, but it sounds like Edge might be getting the same treatment there.

To make VSCode use your OS's actual default browser, you'll need to prefix your NPM script entry with an assignment statement that clears the value of the BROWSER variable. It'll look something like this:

"scripts": {
  "frontend": "BROWSER= npm start",
  ...
}

Note the empty space after BROWSER= in the command above. This sets the value of the variable to [nothing], which triggers VSCode using your OS default browswer.

brnt
  • 153
  • 2
  • 9
0

To solve this, I need to give a default setting in vscode. It was empty, when it's empty, vscode will open edge, that's their favorite browser, it's hard code in their app, so open the vs setting and set the default to chrome. Before I set the default to chrome. it was empty "".

angry kiwi
  • 10,730
  • 26
  • 115
  • 161