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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悶 yarn set version on Node.js <18 #5829

Open
arcanis opened this issue Oct 23, 2023 · 7 comments
Open

馃悶 yarn set version on Node.js <18 #5829

arcanis opened this issue Oct 23, 2023 · 7 comments

Comments

@arcanis
Copy link
Member

arcanis commented Oct 23, 2023

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": "yarn@3.6.4" 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.

@arcanis arcanis pinned this issue Oct 23, 2023
@arcanis arcanis changed the title 馃悶 yarn set version on Node 12 / 14 / 16 馃悶 yarn set version on Node.js <18 Oct 23, 2023
@sivnath-pt
Copy link

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

@brunozoric
Copy link

brunozoric commented Oct 24, 2023

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

@vipul-nema
Copy link

vipul-nema commented Oct 25, 2023

@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.

@litinskii
Copy link

FROM node:16.16.0

RUN yarn set version 3.6.4

RUN touch yarn.lock
RUN yarn install

works for me

@arcanis
Copy link
Member Author

arcanis commented Oct 25, 2023

@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.

@remus-selea
Copy link

remus-selea commented Oct 29, 2023

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

@merceyz
Copy link
Member

merceyz commented Oct 29, 2023

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 yarn@1.22.19 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@arcanis @merceyz @litinskii @brunozoric @vipul-nema @remus-selea @sivnath-pt and others