Skip to content

🐞 yarn set version on Node.js <18 #5829

Open

Description

@arcanis

I open this thread to cover an issue we noticed regarding Yarn 3.x when used with versions of Node.js lower than 18. It's a little complex, so it's worth opening a thread outlining the problem and the progress on solving it.

What happens?

Running yarn set version on Yarn 1.x project will cause it to crash if running with versions of Node.js lower than 18. In particular this happens even when running yarn set version 3.6.4, which one would expect to work (since 3.x supports both Node.js 14 and 16).

Why does that happen?

As you may know, Yarn 1.x has a different codebase than modern releases. To make yarn set version work there, Yarn 1.x actually pulls the latest version of Yarn and forwards the yarn set version call to it. Unfortunately, it always pulls the latest build - so when we published Yarn 4.0 as stable (which drops support for both Node.js 14 and 16), things broke.

Why did we miss it?

It's not a common problem. The installation guide for 3.x releases recommended checking-in the Yarn binary, so running yarn set version on CI isn't the most common experience - typical projects already have 3.x installed in their repo, so they don't need to pull the binary at image time.

How can you workaround it?

The easiest solution is to not use yarn set version with Node.js 12 / 14 / 16. Assuming you cannot upgrade to Node.js 18.x, here are some things you can try:

  • Download the latest 3.x release (link), store it in your project, and add a yarnPath setting in your .yarnrc.yml.

Or, for Node.js 16.x users:

  • You can enable Corepack and manually add a "packageManager": "[email protected]" field to your package.json.

  • You can also try adding export YARN_IGNORE_NODE=1 to your CI, which will simply bypass the compatibility check.

Or, for Node.js 12.x / 14.x users:

  • Make sure you use Yarn without Corepack. We released a mitigation which should restore the original behaviour, as long as you don't use Corepack.

What are we doing to fix that?

Ideally we'd like to "unbreak" it without you having to do anything. We already shipped a mitigation which should help people running Yarn without Corepack, but if you use Corepack things things get quite difficult, and I'm not sure it'll be possible. The best we can do will probably be to release a fix in Yarn 1.x, but older Node.js 12 / 14 / 16 Docker images probably have outdated global Yarn binaries in the first place, so releasing an hotfix won't help.

We're sorry about this problem, and we have plans to avoid them in the future. For now, I suggest to try the listed workarounds and let us know if none of them work for you. I'll update this post as needed.

Activity

  1. pinned this issue on Oct 23, 2023
  2. changed the title [-]🐞 `yarn set version` on Node 12 / 14 / 16[/-] [+]🐞 `yarn set version` on Node.js <18[/+] on Oct 23, 2023
  3. sivnath-pt commented on Oct 24, 2023

    @sivnath-pt

    Any workaround so far a part from the version upgrade? We are currently using node.js 14 and 16

  4. brunozoric commented on Oct 24, 2023

    @brunozoric

    What I did was:

    • YARN_IGNORE_NODE=1 yarn set version berry
    • YARN_IGNORE_NODE=1 yarn set version 3.6.4
    • use yarn on node <18
      hope it helps
  5. vipul-nema commented on Oct 25, 2023

    @vipul-nema

    @arcanis - Issue seems fixed today automatically , Did your team publish any fix. ?

    we were using - RUN yarn set version 3.5.0 in docker file.
    and it was giving same error.

    We would enable corepack too now.

  6. litinskii commented on Oct 25, 2023

    @litinskii

    FROM node:16.16.0

    RUN yarn set version 3.6.4

    RUN touch yarn.lock
    RUN yarn install

    works for me

  7. arcanis commented on Oct 25, 2023

    @arcanis
    MemberAuthor

    @arcanis - Issue seems fixed today automatically , Did your team publish any fix. ?

    Yes, the mitigation I mentioned in the post:

    Or, for Node.js 12.x / 14.x users:

    • Make sure you use Yarn without Corepack. We released a mitigation which should restore the original behaviour, as long as you don't use Corepack.

    In your case you're not using Corepack on those old Node.js images, so our mitigation was sufficient. It's probably the same for most people, but to be careful I preferred to list alternative strategies.

  8. remus-selea commented on Oct 29, 2023

    @remus-selea

    This issue occurs with node 20.x as well. yarn set version 3.6.4 sets 4.0.1 instead of 3.6.4

    image

  9. merceyz commented on Oct 29, 2023

    @merceyz
    Member

    That's a bug in Yarn v1 and not related to the Node.js version you're using, for example it happens on Node.js v18 as well:

    $ docker run --rm -it node:18.18.2 bash -c "corepack enable && corepack [email protected] set version 3.6.4 && yarn --version"
    4.0.1

    @arcanis Seems we need to update https://github.com/yarnpkg/yarn/blob/98036fccb545e4604e9e1ea710dff4e18d7dcc28/src/cli/commands/policies.js#L170 to use the version range provided by the user.

  10. anilgsharma900 commented on Jul 27, 2024

    @anilgsharma900

    This issue occurs with node 20.x as well. yarn set version 3.6.4 sets 4.0.1 instead of 3.6.4

    image

    I am also getting same error, I am using node 20 and yarn classic version 1.22.22 . I resovled it after mentioned "packageManager": "[email protected]"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions