--use-npm should be automatically enabled with npx and npm init/create
See original GitHub issueIs 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:
- Created 4 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top GitHub Comments
yarn 2 doesn’t support create, so maybe we should just stick to npx for now
Update:
process.env.npm_config_user_agent
can be used to detectyarn create
, butnpm create
andnpx
do not support it. This means we can determine when yarn is used, but we can’t distinguish between using npm/npx or usingcreate-react-app
directly.Instead, we could change
create-react-app
andnpx create-react-app
to default to npm, but replacenpx create-react-app
withyarn create-react-app
andnpm 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 withyarn create react-app
.