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.

Yarn is used automatically with no obvious way to use npm instead

See original GitHub issue

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).

Issue Analytics

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

github_iconTop GitHub Comments

36reactions
gaearoncommented, Nov 1, 2017

How about:

create-react-app app --use-npm

?

3reactions
gaearoncommented, Jan 15, 2018

This is out! Please let us know if something doesn’t quite work. https://github.com/facebookincubator/create-react-app/releases/tag/v1.1.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make create-react-app use npm instead of yarn?
You can either. 1) Remove yarn.lock , and running npm i ,. or. 2) Run create-react-app app --use-npm.
Read more >
NPM vs Yarn Cheat Sheet - Red Shift - Infinite Red
Yarn is basically a new installer, where NPM structure and registry is the same.
Read more >
Configuration options | Yarn - Package Manager
Yarn is a modular package manager that can resolve packages from various sources. As such, semver ranges and tag names don't only work...
Read more >
How to Force Use Yarn or NPM
In this short post, I'm going to show you how to prevent the usage of npm or yarn, depending on your needs. This...
Read more >
Why do most React projects seem to use Yarn rather than ...
It is very simple. Same as any other package. You need to install yarn or just do `sudo npm install yarn -g` then...
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