nodejs/corepack

Corepack failed to install yarn when yarnPath is set

Closed this issue · 3 comments

I have a .yarnrc file at the root of my project with yarnPath: .yarn/releases/yarn-3.4.1.cjs. I also configured packageManager to yarn.

After I do:

corepack enable
yarn set version 3.4.1

Or any other yarn cmd, I face the following issue:

  1. corepack detect yarn and start downloading it on the first use
    ! Corepack is about to download https://repo.yarnpkg.com/3.4.1/packages/yarnpkg-cli/bin/yarn.js
  2. But at the same time yarn access the .yarnrc.yml and try to access .yarn/releases/yarn-3.4.1.cjs, which isn't downloaded yet. It results in the following error:
Internal Error: The "yarn-path" option has been set (in /project/.yarnrc.yml), but the specified location doesn't exist (/project/.yarn/releases/yarn-3.4.1.cjs).

Deleting yarnPath parameter solve the issue but corepack adds yarnPath, so I need to clean this parameter whenever I push my changes, otherwise it results in this issue

That seems to be a Yarn issue, not Corepack's. If you run yarn set version 3.4.1, you tell Yarn to do the version management. If you instead ask Corepack to manage your Yarn version (e.g. corepack use yarn@3.4.1), it should behave as expected.

Closing as there is nothing to be done on our side, it seems to be a problem of documentation on Yarn side (or maybe yarn set version should detect when run from Corepack?), I suggest you open an issue on their repo. Let me know if you think I'm missing something and this should be reopen.

/cc @arcanis

or maybe yarn set version should detect when run from Corepack

It already does starting from v4 https://yarnpkg.com/cli/set/version#details

By default it only will set the packageManager field at the root of your project, but if the referenced release cannot be represented this way, if you already have yarnPath configured, or if you set the --yarn-path command line flag, then the release will also be downloaded from the Yarn GitHub repository, stored inside your project, and referenced via the yarnPath settings from your project .yarnrc.yml file.

The documentation lacks a note on this section of code which falls back to yarnPath if you're not using Corepack:
https://github.com/yarnpkg/berry/blob/c0cb6a503a9821a5809b30999d8abc90452d86bb/packages/plugin-essentials/sources/commands/set/version.ts#L222-L225

That seems to be a Yarn issue, not Corepack's. If you run yarn set version 3.4.1, you tell Yarn to do the version management. If you instead ask Corepack to manage your Yarn version (e.g. corepack use yarn@3.4.1), it should behave as expected.

Closing as there is nothing to be done on our side, it seems to be a problem of documentation on Yarn side (or maybe yarn set version should detect when run from Corepack?), I suggest you open an issue on their repo. Let me know if you think I'm missing something and this should be reopen.

/cc @arcanis

corepack use yarn@3.4.1 behave in the same way with yarnPath but it does not set it up