berry: [Bug] Can't switch back to Yarn v1 after trying out Yarn v2

  • I’d be willing to implement a fix

Describe the bug

I wanted to try out Yarn v2, so I did yarn set version 2. This worked. But now I can’t switch back to v1:

> yarn set version 1
^[➤ YN0000: Selecting the highest release amongst 1.22.0 and 18 others
➤ YN0000: Downloading https://github.com/yarnpkg/yarn/releases/download/v1.22.0/yarn-1.22.0.js
➤ YN0000: Saving the new release in .yarn/releases/yarn-1.22.0.js
➤ YN0000: Done in 2.35s

> yarn -v
2.0.0-rc.29

To Reproduce

  1. Start with a regular Yarn 1 installation on macOS, installed via brew.
  2. Run yarn set version 2
  • Running yarn -v now prints 2.0.0-rc.29.
  1. Run yarn set version 1
  • The output makes it look like this worked, but it didn’t – yarn -v still prints 2.0.0-rc.29.

Environment if relevant (please complete the following information):

  • OS: macOS
  • Node version: v12.13.0
  • Yarn version: 2.0.0-rc.29

Additional context

Sorry if I’m missing something obvious - I don’t know much about Berry/Yarn 2, I just wanted to try it out, and now I can’t get back to Yarn 1.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 16
  • Comments: 17 (4 by maintainers)

Most upvoted comments

I “fixed” it my going into my users root directory and executing yarn set version ^1. Now it’s globally back to v1

i had a default in my root, deleting it did the trick

cat ~/.yarnrc.yml 
> yarnPath: ".yarn/releases/yarn-berry.cjs"

rm -f ~/.yarnrc.yml

npm install -g 'yarn@1.22.1'

yarn -v
> 1.22.10

on mac

$ cd ~/
$ yarn set version classic

worked for me

If you enabled yarn via corepack enable from above node v16.14.0, just run corepack disable, then install it the old way like npm i -g yarn@1.22.1.

I’m not at my computer at the moment, but I’m pretty sure you’ll find a .yarn directory in your home directory, if you delete that you should be able to install v1 again. (I had this problem when I first started using v2 as well)

i had a default in my root, deleting it did the trick

cat ~/.yarnrc.yml 
> yarnPath: ".yarn/releases/yarn-berry.cjs"

rm -f ~/.yarnrc.yml

npm install -g 'yarn@1.22.1'

yarn -v
> 1.22.10

If not work Just put the --force parameter in install

A detail is that .yarnrc.yml can live in any ancestor folder. It seems like it’s generated where the command is run. So, if your project is in ~/Projects/MyApp, it can be in ~/.Projects

There isn’t a bug per se - yarn set version updates the .yarnrc.yml file located in the current project, that’s the intended behaviour. The problem is that you have a yarnPath even above, but that isn’t supposed to happen - our docs never mention to run yarn set version at the root or anywhere else than your project. It’s technically a user bug that you ended up in that situation (although it’s a UX bug that you can get into this situation).

That said, I know it’s a common problem, and we’ll likely try to address that somehow in a future release - perhaps by forbidding to run Yarn in the home directory, to avoid accidental commands. But it comes with side effects (I imagine some Docker setup are fine with running Yarn from the home directory), so it hasn’t been a priority so far.

Additionally, with the 4.0 we’re making Corepack the preferred way to install Yarn, so yarnPath should be even less common.

yarn set version ^1

doesn’t work for me, I need to remove .yarnrc.yml then running yarn works right away.

I’m not sure there’s anything actionable on our side at the moment, so I’m going to close this issue.