2

I have been working with React.js for a couple months now, developing using VS Code, Chromium-based browsers (ditched Chrome, switched to Brave as default browser) and a Windows machine (Windows 10).

Recently, my friend have recommended that I switch to using Firefox for development, and as lazy as developers can go, I wanna ask how to configure such that when I do npm start, localhost:3000 will appear in Firefox instead of my original default browser. I do not want to change my default browser.

Update

From recommendations I have found this other post:
create-react-app: How do I "npm start" with a specific browser?

Further comments are still welcome XD

on9_jai
  • 100
  • 1
  • 7

3 Answers3

3

You don't need to run any command in cmd or make changes to any scripts. Just make default the browser, you want for HTTP file extension. I have Edge as default for everything, just changed HTTP to Chrome and Yes! React app opens now in Chrome.

enter image description here

RBT
  • 24,161
  • 21
  • 159
  • 240
0

On Linux(Ubuntu 20.04). Edit Your package.json like that:

"scripts": {
    "start": "BROWSER=firefox react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

Type npm start and Voila :-P

On Win 10. Create an .env file in the root directory with line like this BROWSER=firefox Run npm start and You are done:-) Best Regards ;-)

MarioG8
  • 5,122
  • 4
  • 13
  • 29
  • A new error appeared: – on9_jai Oct 09 '21 at 17:26
  • > BROWSER=firefox react-scripts start 'BROWSER' is not recognized as an internal or external command, operable program or batch file. npm ERR! code ELIFECYCLE npm ERR! errno 1 – on9_jai Oct 09 '21 at 17:27
  • Is there some additional setup I should do for the script to be able to understand `BROWSER=firefox` ? – on9_jai Oct 09 '21 at 17:27
  • I checked it a moment ago on two browsers. And it works for me! ??! "BROWSER = firefox react-scripts start", "BROWSER = google-chrome react-scripts start", Linux Ubuntu 20.04 Today I was updating node.js to 14.18.0, npm 8.0.0..React => "^ 17.0.2" – MarioG8 Oct 09 '21 at 17:38
  • Oh I am doing this on a Windows machine, which I checked from the other post I found was somehow incompatible with directly using `BROWSER=firefox`. Thanks for this though, never would've found the other post without your answer! – on9_jai Oct 09 '21 at 17:42
  • I solved the problem on Windows 10 Create an .env file in the root directory with line like this BROWSER = firefox Run npm start and You are done! :-D – MarioG8 Oct 09 '21 at 18:55
0

I would set the BROWSER environment variable in your linux environment instead of the project-specific package.json file (or inside of a .env file) if you are using the Windows Subsystem for Linux (WSL) on your Windows 10 machine and always want to connect to the React development server from your Firefox browser.

Assuming you are using WSL2: open a WSL2 shell and enter the following command:

sudo nano ~/.bashrc

Add export BROWSER='firefox' at the end of the file, exit the nano editor (CTRL+X) and save (Y) when prompted. Enter the following command in the linux bash shell:

exit

Now, relaunch the WSL2 linux shell and start the React development server again. Firefox should start automatically, pointing to your development server on localhost.