Yarn: Specify fixed yarn version?

Created on 8 Sep 2017  路  16Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?

feature / question

How can I specify a fixed Yarn version for a given project so that everyone in that project has to use this version? For example I have a .nvmrc in that project. With that I can ensure that everyone should use the same node version. How can I do that with Yarn? Is there a option in .yarnrc that I overlooked? I read #4115 but that only specifies a path but not a version number.

Most helpful comment

All 16 comments

@screendriver you can use #4115 and check in a single-file bundle of a specific yarn version and voila!

Alternatively, consider using something like Docker or Vagrant as it'd allow the entire system to be identical for everyone.

Thank you for your help.

@ravicious this solution seems to be the best for us 馃憤 We will use that.

@BYK I don't really understand #4115 and how to do that 馃

@Daniel15 unfortunately this is a little bit to much overhead for just a single "check the yarn version". We already used the Nix package manager for that but it overcomplicates everything. But thank you.

@screendriver, @ravicious engines field wont help with that, see https://github.com/yarnpkg/yarn/issues/2800

I just checked with yarn 1.0.1 and if I specify "yarn": ">2" in the "engines" field, yarn install fails.

I just checked with yarn 1.0.1 and if I specify "yarn": ">2" in the "engines" field, yarn install fails.

I tried the same and it works as well in my case 馃

Turns out my v0.27.5 is simply too dated for this...
As per https://github.com/yarnpkg/yarn/releases this feature was added with https://github.com/yarnpkg/yarn/pull/3675 in v1.0.0 (also in v0.28.0) It's time to upgrade I guess :)

@screendriver I see you've closed the issue but from what I understand, you're still trying to figure out a solution. Do you need any help from us?

You've asked about #4115 and here's how I'd use that:

  • Download and check-in a single-file bundle of yarn for the version I want into my repo
  • Add a .yarnrc file to the root of my repo with the line yarn-path "./yarn.js" in it where yarn.js is the one you've downloaded.

If everyone has yarn 1.0+ installed on their system, it will defer to whatever yarn version is checked in to your repo, that can be lower than 1.0.

Apologies for not documenting this feature properly yet.

Download and check-in a single-file bundle of yarn

What does that mean? I created a .yarnrc file and added yarn-path "./yarn.js". But what should yarn.js contain? Can I download Yarn as a single JavaScript file and name it yarn.js?

PS: I closed the issue because { "engines": { "yarn": "1.0.1" }} does work in my case. If anyone has not 1.0.1 installed on it's machine Yarn complains about it and does not install anything (that's exactly what I wanted)

Can I download Yarn as a single JavaScript file and name it yarn.js?

You sure can! You can grab yarn-1.0.1.js over on the releases page (https://github.com/yarnpkg/yarn/releases/tag/v1.0.1). This is a single JS file containing the whole of Yarn. If you wanted to, you could commit it to source control and everyone would use the checked in version.

PS: I closed the issue because { "engines": { "yarn": "1.0.1" }} does work in my case.

You might want to do something like "yarn": ">=1.0.1" so that newer versions (like 1.0.2) work too.

Oh cool, I didn't know that 馃憤

I didn't added "yarn": ">=1.0.1" on purpose because in the past we had sometimes problems if the Yarn version does not match exactly on every machine. It generated a slightly different yarn.lock and our build broke.

@Daniel15 do you know if there is a minified / compressed version of yarn.js?

I don't think there is. You could try run it through UglifyJS or something similar and see how much of a difference it makes.

@screendriver I would suggest using at least "yarn": "~1.0.1" if not "yarn": "^1.0.1". We are now committed to not making breaking changes in major versions as part of our 1.0 release.

We are now committed to not making breaking changes in major versions as part of our 1.0 release.

馃憤

In the meantime I added my own yarn.js and yarn-path to my .yarnrc file so it doesn't matter anymore 馃槈 I also deleted the engines node in my package.json because it's not needed anymore 馃槑

Was this page helpful?
0 / 5 - 0 ratings