Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: set version issue #6310

Closed
1 task
hangya-fadir opened this issue May 24, 2024 · 9 comments
Closed
1 task

[Bug?]: set version issue #6310

hangya-fadir opened this issue May 24, 2024 · 9 comments
Labels
bug Something isn't working waiting for feedback Will autoclose in a while unless more data are provided

Comments

@hangya-fadir
Copy link

hangya-fadir commented May 24, 2024

Self-service

  • I'd be willing to implement a fix

Describe the bug

in case the global yarn version is 1.22.21 i can't switch to yarn 4.2.2 if the package.json already contains "packageManager": "[email protected]"

NOTE: this is used in Ci/CD pipeline, e.g no way to leave the project folder

error This project's package.json defines "packageManager": "[email protected]". However the current global version of Yarn is 1.22.21.

Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.

To reproduce

  1. yarn set version 1.22.21
  2. git clone <your project with [email protected]>
  3. yarn -> see the console for the error
  4. yarn set version XXXX
  5. yarn dlx XXX

Environment

System:
    OS: macOS 14.1
    CPU: (12) arm64 Apple M3 Pro
  Binaries:
    Node: 22.1.0 - /private/var/folders/5f/0b9zhgpd1g132gtzrlzlt7rh0000gn/T/xfs-5e99bc67/node
    Yarn: 4.2.2 - /private/var/folders/5f/0b9zhgpd1g132gtzrlzlt7rh0000gn/T/xfs-5e99bc67/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v22.1.0/bin/npm

Additional context

also the yarn dlx -q envinfo --preset jest is not working in the above case

@hangya-fadir hangya-fadir added the bug Something isn't working label May 24, 2024
@clemyan
Copy link
Member

clemyan commented May 24, 2024

You need to enable Corepack by running corepack enable before running yarn commands. See https://yarnpkg.com/corepack for more information

@clemyan clemyan added the waiting for feedback Will autoclose in a while unless more data are provided label May 24, 2024
@akwodkiewicz

This comment was marked as off-topic.

@MikeMcC399
Copy link

Even if I start out with Yarn 1.22.19 installed and corepack not enabled, I still run into this issue:

$ corepack disable
$ npm install [email protected] --global
$ yarn set version stable
➤ YN0000: You don't seem to have Corepack enabled; we'll have to rely on yarnPath instead
➤ YN0000: Downloading https://repo.yarnpkg.com/4.2.2/packages/yarnpkg-cli/bin/yarn.js
➤ YN0000: Saving the new release in .yarn/releases/yarn-4.2.2.cjs
➤ YN0000: Done with warnings in 0s 289ms
$ yarn set version classic
➤ YN0000: Downloading https://classic.yarnpkg.com/latest.js
➤ YN0000: Saving the new release in .yarn/releases/yarn-classic.cjs
➤ YN0000: Done in 2s 497ms
$ yarn set version stable
error This project's package.json defines "packageManager": "[email protected]". However the current global version of Yarn is 1.22.22.

Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.

Enabling corepack will work around this issue, however considering that corepack is still classified as experimental, it is problematic to force its use in a production environment.

@arcanis

This comment was marked as off-topic.

@arcanis
Copy link
Member

arcanis commented May 27, 2024

in case the global yarn version is 1.22.21 i can't switch to yarn 4.2.2 if the package.json already contains "packageManager": "[email protected]"

As mentioned in the error message, if the package contains a packageManager field, then you're expected to use Corepack. You can use also define SKIP_YARN_COREPACK_CHECK=1 as a workaround.

Enabling corepack will work around this issue, however considering that corepack is still classified as experimental, it is problematic to force its use in a production environment.

If the project contains packageManager, it's that it's meant to use Corepack. If you don't want to force its use on an environment, don't add the packageManager field (or use the environment variable suggested above).

@arcanis arcanis closed this as completed May 27, 2024
@MikeMcC399
Copy link

@arcanis

Thanks for the workaround SKIP_YARN_COREPACK_CHECK=1!

It appears that this issue is caused by the CLI command

yarn set version classic

I would expect this command to remove

{
  "packageManager": "[email protected]"
}

from package.json. This entry was put there by the previous command

yarn set version stable

Or is it expected that yarn set version classic would leave the entry for [email protected] in package.json?

@akwodkiewicz

This comment was marked as off-topic.

@arcanis
Copy link
Member

arcanis commented May 27, 2024

Or is it expected that yarn set version classic would leave the entry for [email protected] in package.json?

Yarn Classic does the check before spawning any Yarn command - including set version. Changing that would require adding more spaghetti code into the Classic CLI bootstrap; I'd really prefer to avoid that.

@Esaron
Copy link

Esaron commented May 28, 2024

This, or something that presents the same, started hitting us as well (in addition to the other issue I opened that's referenced earlier in this comment chain).

Packing ember-ajax-fetch@https://github.com/expel-io/ember-ajax-fetch.git#commit=0341a43f615f54a5e6d448eb19392c54aefb262d from sources
Using Yarn Classic for bootstrap. Reason: "__metadata" key not found in yarn.lock, must be a Yarn classic lockfile

➤ YN0000: Downloading https://classic.yarnpkg.com/latest.js
➤ YN0000: Saving the new release in .yarn/releases/yarn-classic.cjs
➤ YN0000: Done in 1s 128ms

error This project's package.json defines "packageManager": "[email protected]". However the current global version of Yarn is 1.22.22.

Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.

The odd thing is that we are using corepack. Even if I run corepack enable explicitly before running yarn (just to be absolutely certain of that claim), packing packages from source fails. Before the recent updates to the 1.22.22 version, we weren't seeing this issue. Nothing in our environment or Yarn config has changed. If I run yarn set version 1.22.22, and use Yarn Classic for the build, things work again, but I think that's expected based on how these packages are handled by 1.x.

An interesting thing to note is that running yarn set version 1.22.22 works as expected and sets the global version to 1.22.22, but if I subsequently run yarn set version 4.2.2, I see the exact error that's being output during packing:

error This project's package.json defines "packageManager": "[email protected]". However the current global version of Yarn is 1.22.22.

Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.

Editing with new info:

Our issue seems to have been that running yarn set version [version] creates a package.json and .yarnrc.yml file wherever it's run, regardless of whether that location is a Yarn project. We ran it in the parent directory of our project to set the global Yarn version as part of a previous set of commands, but there was a mismatch between the created package.json value of packageManager and the value specified by our actual project's package.json. Once we deleted this (erroneously created?) package.json, we were able to switch versions again in the project, which allowed the builds from source to work as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting for feedback Will autoclose in a while unless more data are provided
Projects
None yet
Development

No branches or pull requests

6 participants