question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

--use-npm should be automatically enabled with npx and npm init/create

See original GitHub issue

Is your proposal related to a problem?

By default create-react-app will create new projects with yarn if it is installed, even if one of the following npm commands is used to create it:

npx create-react-app
npm init react-app
npm create react-app

In this case, I think it’s likely that the user intends on using npm for their new app, even if they use yarn for other projects. I’ve had to keep both package managers installed regardless of my preference to contribute to different projects on the same machine. This lead to some situations where I wanted to use npm by default, but I would keep forgetting that create-react-app would use yarn because I still had it installed.

Describe the solution you’d like

Ideally, it would help if create-react-app could detect when it’s being called via npx (which is also used by npm create/init) and default to turning on --use-npm in this case. create-react-app should still default to yarn when it’s installed and the user directly calls create-react-app to prevent confusion and breaking changes.

Describe alternatives you’ve considered

Of course you could try to remember to use --use-npm, but it’s easy to forget if you have yarn installed and that create-react-app still requires then flag with npm/npx commands. I think this is worth figuring out for the improved developer experience, especially since npm/yarn users frequently run into bugs when switching package managers accidentally (for example, when trying to use npm and not remembering that create-react-app was using yarn).

Additional context

I’ve attempted this myself, though unfortunately npx don’t seem to provide easy ways to detect its usage (unlike yarn which has a parent process and tons of environment variables). Instead, npx will replace the current process with the new command and provide exactly the same environment variables, making it look very similar to the Node environment that commands like create-react-app use. I’d be happy to help with implementing this if someone can help me find other ways to detect npx’s usage.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nickmccurdycommented, Feb 11, 2020

yarn 2 doesn’t support create, so maybe we should just stick to npx for now

0reactions
nickmccurdycommented, Sep 15, 2019

Update: process.env.npm_config_user_agent can be used to detect yarn create, but npm create and npx do not support it. This means we can determine when yarn is used, but we can’t distinguish between using npm/npx or using create-react-app directly.

Instead, we could change create-react-app and npx create-react-app to default to npm, but replace npx create-react-app with yarn create-react-app and npm create react-app in the docs so we always have a way of telling them apart. Meanwhile, process.env.npm_config_user_agent could be used to enable yarn automatically with yarn create react-app.

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm-init
The init command is transformed to a corresponding npm exec operation as follows: npm init foo -> npm exec create-foo; npm init @usr/foo...
Read more >
npm vs npx — What's the Difference? - freeCodeCamp
It provides a way for developers to install packages both globally and locally. Sometimes you might want to take a look at a...
Read more >
npm Documentation
Run packages without downloading using npx. Share code with any npm user, any where. Restrict code to specific developers. Form Orgs (organizations) to...
Read more >
Comparing NPM (Node Package Manager) and NPX (Node ...
js packages to use them in our application. It makes it easier for developers to share and reuse open source code by enabling...
Read more >
Install CDK for Terraform and Run a Quick Start Demo
To install the most recent stable release of CDKTF, use npm ... cdktf help cdktf Commands: cdktf init Create a new cdktf project...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found