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

fix: browser selection via env variable

Open FloydJohn opened this issue 3 years ago • 25 comments

Hi everyone,

this PR fixes the opening of a browser of choice, selected through the BROWSER environment variable, when starting a generated project.

After migrating to CRA v5.x the feature stopped working (see #11873, #11844, #11942, #11917, #12275).

Browsing the documentation for the [email protected] package (available here) I noticed that the syntax for opening an URL using a specified browser was updated.

This PR includes two small changes:

  • The updated syntax for opening a browser is now used
  • Since the open package natively supports passing an array of arguments to the application, we no longer need to concatenate the arguments before the call

To test this feature I followed this test plan:

  • Create a new .env file in the template project, containing for example the value BROWSER=google-chrome-stable. The browser name could change based on OS or linux distro.
  • Start the template project with npm run start. A new tab should open in the specified browser.
  • Stop the process and remove the newly created .env file.
  • Start again the project with npm run start: it should open on the default browser.

FloydJohn avatar Jan 03 '22 16:01 FloydJohn

Hi @FloydJohn!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

facebook-github-bot avatar Jan 03 '22 16:01 facebook-github-bot

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

facebook-github-bot avatar Jan 03 '22 17:01 facebook-github-bot

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

facebook-github-bot avatar Jan 03 '22 17:01 facebook-github-bot

@iansu @mrmckeb Can anyone of you look at this PR?

Karthick-FK avatar Jan 24 '22 06:01 Karthick-FK

This Process still not working. in my .env.local I put BROWSER=firefox

4nkit-5hukla avatar Feb 01 '22 03:02 4nkit-5hukla

HI @4nkit-5hukla, thanks for the feedback!

I tested this fix again, and I can confirm that BROWSER=firefox correctly launches the browser on my Linux and Windows installs.

I'll leave here the steps to test this fix:

  • As this is not merged, you'll have to clone my fork on the correct branch: git clone https://github.com/FloydJohn/create-react-app -b fix-browser-env
  • Create a .env file here: packages/cra-template/template/.env
  • Insert in this .env file the line BROWSER=firefox. Test that on your terminal you can start Firefox by issuing the firefox command
  • Launch from the repo root npm i && npm run start

Firefox should open as expected.

To make sure that you created the .env file in the correct path, you can always add a variable like REACT_APP_TEST=test and display the loaded env variables by adding a line like {JSON.stringify(process.env)} on the template.

Hope that this helped, let me know if it works as expected!

FloydJohn avatar Feb 01 '22 08:02 FloydJohn

After having this problem myself, I did some debugging and came to the same conclusion. I was going to create a pull request myself, but @FloydJohn beat me to it. I can confirm that this fix solves the problem. (Another fix would be to revert to [email protected].)

renaatdemuynck avatar Mar 17 '22 13:03 renaatdemuynck

I can confirm that this fixes #11917.

martiniil avatar May 06 '22 12:05 martiniil

TIP: For now, this works as a temporary fix in package.json:

  "resolutions": {
    "open": "7.4.2"
  },

renaatdemuynck avatar May 16 '22 11:05 renaatdemuynck

Is there an update on merging this PR?

antingle avatar Sep 07 '22 20:09 antingle

When this PR will be merge ?

tmanson avatar Sep 26 '22 10:09 tmanson

@iansu @mrmckeb Please merge when you have time :)

chrisschuller avatar Oct 11 '22 15:10 chrisschuller

Could this be merged? Its a very annoying issue.

AFCMS avatar Oct 18 '22 14:10 AFCMS

Up

rs7 avatar Nov 09 '22 14:11 rs7

Hello. Is there an update on when would this be ready? Much appreciated. Thanks. @iansu @mrmckeb

wahabmirjan avatar Nov 26 '22 00:11 wahabmirjan

Any updates on merging this PR? @iansu @mrmckeb

OmKakatkar avatar Dec 22 '22 05:12 OmKakatkar

TIP: For now, this works as a temporary fix in package.json:

  "resolutions": {
    "open": "7.4.2"
  },

This workaround didn't work with npm for me. Instead I've used the following (requires npm-cli 8.3 or later):

    "overrides": {
        "open": "7.4.2"
    }

I had to also remove node_modules and package-lock.json before running npm install for the override to work.

elringus avatar Dec 27 '22 12:12 elringus

It would be nice to merge this PR.

DamienCassou avatar Apr 26 '23 18:04 DamienCassou

hi, why is this still not merged?

sKopheK avatar Aug 06 '23 21:08 sKopheK

merge asap wtf ffs. what r u waiting for ? :D

ridl27 avatar Aug 19 '23 22:08 ridl27

look at when the last version was released: https://www.npmjs.com/package/create-react-app (a year ago) seems like the project is not really alive, better switch to some modern boilerplate

sKopheK avatar Aug 20 '23 07:08 sKopheK

look at when the last version was released: https://www.npmjs.com/package/create-react-app (a year ago) seems like the project is not really alive, better switch to some modern boilerplate

whats ur choice bro?

ridl27 avatar Aug 29 '23 12:08 ridl27

look at when the last version was released: https://www.npmjs.com/package/create-react-app (a year ago) seems like the project is not really alive, better switch to some modern boilerplate

whats ur choice bro?

for one existing project based on CRA i've switched to vite, so far better. but im not that experienced with these tools so can only recommend it based on how the project is active

sKopheK avatar Aug 29 '23 13:08 sKopheK

Goodnight. Any updates on this pull request?

BraianS avatar Mar 17 '24 23:03 BraianS