volta icon indicating copy to clipboard operation
volta copied to clipboard

If global yarn is v3 can't pin yarn@1

Open chenmnkken opened this issue 2 years ago • 7 comments

In my macOs Ventura, the global Yarn is 3.3.1, update before is v1, Volta version is 1.1.1, global Node version is 16.13.1.

My some project Yarn version is 1.22.11 and Node is 14.17.6 in Volta config.

But in project root dir run node -v is print version is 14.17.6, run yarn -v is print version is 3.3.1, so I can't use v1 yarn in my project.

In project root dir run volta install yarn@1 is print success, and run volta pin yarn@1 is print success too.

chenmnkken avatar Feb 02 '23 06:02 chenmnkken

Hi @chenmnkken, thanks for reporting! Is it possible that you have a global version of Yarn that is shadowing the Volta shim and causing the incorrect version to be detected? There are a couple of commands you could use to test. What are the outputs of (assuming Linux/Mac, if you're on Windows it's a bit trickier):

which -a volta
VOLTA_LOGLEVEL=debug yarn -v

Those outputs should help explain why you're not seeing the appropriate Yarn version.

charlespierce avatar Feb 07 '23 18:02 charlespierce

Hi @charlespierce, thanks reply.

The command which -a volta is print:

/Users/xxx/.volta/bin/volta

And command VOLTA_LOGLEVEL=debug yarn -v is print:

[verbose] Found default configuration at '/Users/xxx/.volta/tools/user/platform.json'
[verbose] [email protected] has already been fetched, skipping download
[verbose] [email protected] has already been fetched, skipping download
[verbose] [email protected] has already been fetched, skipping download
[verbose] Active Image:
    Node: 18.13.0 from default configuration
    npm: 9.4.0 from default configuration
    pnpm: None
    Yarn: 1.22.11 from default configuration
3.3.1
[verbose] No custom hooks found

I use volta install yarn@1 or volta install yarn@3, install is success, then use volta list check currently active tools, finally yarn version is v3.

I know the yarn v1 to v3 has many break changes, so I'll try to other ways, maybe the yarn v3 install way has problem.

chenmnkken avatar Feb 08 '23 03:02 chenmnkken

That’s very odd! Volta is properly detecting the Yarn version, but then what’s executing is a different version.

Oh, one thing that may be affecting this is that Yarn has its own “pinning” system in a project. Since that’s handled entirely by Yarn after it starts, it will always take precedence. Does this project have a .yarnrc.yml file with a yarnPath set in it? If so, what’s likely happening is Volta is properly launching Yarn 1, but then Yarn’s settings are taking over and passing control over to Yarn 3.

If that’s the case, I believe running yarn set version self would revert that, however their may be some circular indirection with which version launches.

charlespierce avatar Feb 08 '23 17:02 charlespierce

Check if you have an .yarnrc.yml in the home directory. Ran into a similar issue and removing that and .yarn/ seemed to fix it for me.

zvonimirr avatar May 16 '23 10:05 zvonimirr

By tried and tested, volta and corepack has conflict, after reset my node.js and yarn env, use the volta control the yarn version is work fine.

chenmnkken avatar May 19 '23 09:05 chenmnkken

In my case, removing .yarn/ and running yarn set version 1.22.19 resolved the issue (set the version explicitly, assuming it is installed).

jaf7 avatar Jan 19 '24 21:01 jaf7

Ya, if you have used yarn set version in your project any version of yarn you actually execute initially will end up deferring to that checked in version. In other words, volta would actually be executing yarn@1 but if yarn set version was previously ran in the repo for yarn@3 when volta's yarn@1 runs it immediately runs the version checked into the repo (which is why yarn -v shows 3.x version instead of a yarn@1 version).

rwjblue avatar Jan 20 '24 18:01 rwjblue