Yarn is used automatically with no obvious way to use npm instead
Created by: codazoda
Summary
create-react-app uses yarn for the setup if it's installed. I prefer npm alone but I have yarn installed because it's necessary for some of the projects I work on. I'd like to be able to use npm instead of yarn when creating a new app with create-react-app
.
create-react-app tests for yarn by running yarn --version
. Other scripts in the react-scripts
directory then look for the yarn.lock
file and key off of that.
Possible Solutions
I'm prepared to update the code and create a pull request based on the result of this discussion. Here are a few of the solutions I have considered.
- Have create-react-app tell the user it used yarn and simply suggest deleting yarn.lock to use npm instead
- Use an environment variable such as
USE_YARN=no
- Have create-react-app prompt the user if they would like to use yarn if it's installed
- Don't solve the problem
The contributing documentation suggests against using config options, so I didn't offer that as a solution. I'm leaning toward the first solution in that list.
More Solution Details
One option is to simply inform the user that yarn was used and offer the suggestion that they can delete the yarn.lock file to use npm instead. Substituting npm
for the yarn
commands listed above that prompt. This seems like a pretty simple solution but it does require the user delete a file and it also adds some additional messaging to the app that might better belong in documentation somewhere.
Another option is to allow overriding the usage of yarn by looking for an environment variable such as USE_YARN=no
. This would not be obvious to the user but could be covered in the documentation.
We might also solve the problem by having create-react-app prompt the user. The contributing doc suggests that interactivity is preferred over configuration flags. A prompt, however, would interrupt the user every time they run create-react-app just because they have yarn installed. Many users might prefer the default behavior of using yarn so this is an unwanted interruption.
Finally, we could do nothing and a developer could simply delete the yarn.lock
file after creating a new project. This isn't covered in any messaging or documentation, however, so the solution wasn't obvious to me until after I dug into the source code.
Discussion
I'm happy to send a pull request to solve the problem but I'd like to know how the community would like it solved (if at all).