Hi all! Yarn's team lead just released a blog post outlining the first stable release of version 2.
The yarn docs have also switched over to 2.0, with the old site moved to https://legacy.yarnpkg.com.
As far as I can tell, this means a couple of things for Volta:
yarn@berry and since Yarn 2 is developed in a separate repo on GitHub from 1.x (https://github.com/yarnpkg/berry vs. https://github.com/yarnpkg/yarn), Volta's current list of Yarn releases doesn't support the 2x versions, since it uses the releases list for the yarnpkg/yarn repo:Depending on if/when Yarn intends on moving the 2.x versions into the yarnpkg/yarn repo, this will fix itself, but I'm not sure if that is planned.
Both of these issues would be resolved by switching to the parsing the npm registry url for both the latest version and enabling installation of beta releases: https://registry.npmjs.org/yarn
I'm not sure of potential downsides to this approach.
Again, all of these issues may be resolved depending on how Yarn manages the official launch of version 2, but not sure.
Got a speedy reply from the yarn team:
Will the yarnpkg/berry repo be moved into the main yarkpkg/yarn repo?
No, I think it's important to keep the history of the project. If we were to move
yarnpkg/berryintoyarnpkg/yarn, many links would end up broken (unless we purely "take over" the Yarn 1 repo, but I don't want to use the Yarn 1 issue tracker which is in a very sad state).The previous docs site had a url to return the latest version of yarn. It currently redirects to the legacy docs: yarnpkg.com/latest-version. Will this be maintained on the new site, and should it even be used as a retrieval method of the latest version?
I think it will, yes. Right now we wanted to preserve the behaviour pretty much as it was before the Yarn 2 release so that workflows that expect a 1.x release have time to update their workflows if they need to. In a few weeks we'll start switching the tags and
latest-version& friends will be part of it.
So, key takeway鈥攙olta's detection of the latest yarn version can stay the same, but detection of available releases should be changed.
As currently setup, when the yarn team officially switches the latest version to 2.x, volta will be unable to resolve the version and fail to install yarn.
Perhaps instaling yarn should just use the existing package resolution?
https://github.com/volta-cli/volta/blob/master/crates/volta-core/src/tool/package/resolve.rs
We definitely should look at supporting Yarn 2.0. The resolution issues we'll need to be aware of, if needed we can use the package resolution, though that has its own issues since the package that comes from npm currently doesn't include launchers for Windows the way the 1.x tarball does. We have workarounds for that, but it exposes us to an outstanding issue about tools being able to see each other, which we don't currently have with Yarn.
Ideally, Yarn will start providing a tarball again (their docs say that the "other" installers will be available soon), so if that's the case then we can start using that with whatever index Yarn provides.
Additionally, it looks like we need to support Yarn Plug'n'Play, because it appears that Yarn 2.0 is fully built on that. I think that's a relatively simple change, but we'd need to test it to be sure.
We already had supporting custom npm versions as the highest priority, and I think this fits in fairly well with that as a follow-up.
@zackkrida Thanks for compiling all of that documentation in the issue, and for checking with the Yarn team! That makes evaluating the changes a lot easier!
Related: earlier discussion of Yarn Plug'n'Play occurred at #158.
We should at least be able to install and use berry without issues related to volta, since running npm install -g yarn@berry raises an error.
@zackkrida suggestion seems great 馃憤
Details:
Volta error: Global package installs are not supported.
Use `volta install yarn@berry` to add a package to your toolchain (see `volta help install` for more info).
And the recommended command won't run either:
error: Could not parse version "berry"
Please verify the intended version.
Update on this: The core installation support for Yarn 2.0 should be fixed as of Volta 0.8.7. The Plug'n'Play issues outlined in #158 are still outstanding, and will cause globals that are trying to delegate to the local project to fail (since they look in node_modules/.bin which doesn't exist under PnP).
@charlespierce yarn 2 installation is still not working...

It looks like yarn has not been releasing 2.x to npm: https://www.npmjs.com/package/yarn
@billyvg That's a good find, thanks! It looks like Yarn has silently changed their behavior with how they provide their binaries. We'll likely need to investigate deeper if there's a way we can download the packages from the same source that Yarn uses internally in order to provide the appropriate versions.
To use Yarn 2 for the time being, I would recommend using Volta to set a 1.* version of Yarn as your default, and then _not_ pinning Yarn in the package.json but instead using Yarn's approach of yarn set version berry as described here: https://yarnpkg.com/getting-started/install#per-project-install
I did what @charlespierce suggested on a recent project and it actually worked really well! Volta still manages the Yarn 1 installation but delegates all "real" operations to the local Yarn 2 install. The local experience and using the GitHub Action for Volta both work great this way!
Hi, I installed yarn@berry with volta, but it says versino v2.0.0-rc27.
Yarn has been already released v2.4.0
How do I install v2.4.0?
I tried to run yarn version set berry, then it created .yarn and .yarnrc.yml folder. it's a little annoying.
Please someone help.
Hi @ishiijp, as mentioned above, it appears that Yarn has decided to not publish new versions in the npm registry, which is where Volta gets its information. As a result, we don't currently support Yarn 2 within Volta itself. The recommended way forward is to follow Yarn's installation instructions to install Yarn 1 globally (which will be managed by Volta), then use yarn version set berry in a given project to install Yarn 2 for that project.
We may, at some point, support fetching Yarn 2 from whatever source they are using now, however since that method changed at least once without a major version bump, I'm a little wary of tying our implementation to details of Yarn that aren't considered pubic API.
@charlespierce
Thank you for your explanation.
I understand very well.
Most helpful comment
@billyvg That's a good find, thanks! It looks like Yarn has silently changed their behavior with how they provide their binaries. We'll likely need to investigate deeper if there's a way we can download the packages from the same source that Yarn uses internally in order to provide the appropriate versions.
To use Yarn 2 for the time being, I would recommend using Volta to set a 1.* version of Yarn as your default, and then _not_ pinning Yarn in the
package.jsonbut instead using Yarn's approach ofyarn set version berryas described here: https://yarnpkg.com/getting-started/install#per-project-install