Yarn `set version` updates whole yarn plug'n'play cache - yarn-v2

When my project use yarn 3.2.1 and I set the yarn version to canary with yarn set version canary, all the dependencies update in the yarn cache.
I would like to know why this is the case as I just updated the yarn version and not the version of the dependencies of my project and if there is a way to avoid that to not increase the size of my repository.
Thank you for your answer

Related

My action runner for github is failing. How do I resolve yarn: command not found. Process completed with exit code 127?

I was running a self hosted github action runner but my jobs were failing with this error message in the picture. I searched stackoverflow before posting the question but couldn't find any relevant threads. Let me know if there are threads that I missed.
How do I resolve this error so that my github action runner can run my CI builds again?
The built-in GitHub Action runners have yarn installed on them by default but a self-hosted runner won't unless you install it. See relevant issue here: https://github.com/actions/setup-node/issues/182.
If you don't want to install yarn on your self-hosted runner you can install it in the workflows that need it. Just make sure to uninstall it afterward to keep your self-hosted runners clean.
# You'll need to make sure node is installed first
- name: Install Node
uses: actions/setup-node#v3
with:
node-version-file: '.node-version'
- name: Install yarn
run: npm install -g yarn
# Do what you need to do with yarn
# Uninstall when you're done
- name: Clean up
if: always()
run: npm uninstall -g yarn
I realised that the issue was literally as described in the error that for some reason yarn was not found on my computer. This was a little strange as I remembered installing yarn before.
Nevertheless I ran
brew install yarn
And ran brew update and upgrade just in case my homebrew was outdated
brew update
brew upgrade
And it resolved the error and issues.

Yarn: How to upgrade yarn version using terminal?

How should yarn be upgraded to the latest version?
For macOS users, if you installed yarn via brew, you can upgrade it using the below command:
brew upgrade yarn
On Linux, just run the below command at the terminal:
$ curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
On Windows, upgrade with Chocolatey
choco upgrade yarn
Credits:
Added answers with the help of the below answers
https://stackoverflow.com/a/54147594/842607
https://stackoverflow.com/a/53710422/842607
npm install --global yarn
npm upgrade --global yarn
This should work.
Not remembering how i've installed yarn the command that worked for me was:
yarn policies set-version
This command updates the current yarn version to the latest stable.
From the documentation:
Note that this command also is the preferred way to upgrade Yarn - it will work no matter how you originally installed it, which might sometimes prove difficult to figure out otherwise.
Reference
On Linux, just run below command at terminal:
$ curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
After do this, close the current terminal and open it again. And then, run below command to check yarn current version:
$ yarn --version
yarn policies set-version
will download the latest stable release
Referenced yarn docs
https://yarnpkg.com/lang/en/docs/cli/policies/#toc-policies-set-version
For Windows users
I usually upgrade Yarn with Chocolatey.
choco upgrade yarn
npm install -g yarn - solved the issue when nothing happened running npm update --global yarn.
Alternative method to update yarn: curl --compressed -o- -L https://yarnpkg.com/install.sh | bash.
Mac users with homebrew can run brew upgrade yarn.
More details here and here.
Works on all OS's
yarn set version latest
yarn set version from sources
Worked without the second line for me, but it is in the documentation for some reason.
Reference
I had an outdated symlink that was preventing me from accessing the proper bin. I had also recently gone through a node upgrade which means a lot of my newer bins were available in a different folder with what i think was a lower priority
Here is what worked for me:
yarn -v
> 1.15.2
which yarn
> /Users/lfender/.yarn/bin/yarn
rm -rf /Users/lfender/.yarn/bin/yarn
npm uninstall --global yarn; npm install --global yarn
> + yarn#1.16.0
> added 1 package in 0.179s
which yarn
> /Users/lfender/.nvm/versions/node/v12.2.0/bin/yarn
yarn -v
> 1.16.0
If you are not using NVM, the location of your bin installs are likely to be unique to your system
From there, I've switched to doing yarn policies set-version as outlined here https://stackoverflow.com/a/55278430/1426788 to define my yarn version at the repo level
According to https://yarnpkg.com/getting-started/install#updating-to-the-latest-versions
yarn set version <version>
For example to upgrade yarn v1.22.4 to v1.22.10:
yarn set version 1.22.10
I updated yarn on my Ubuntu by running the following command from my terminal
curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
source:https://yarnpkg.com/lang/en/docs/cli/self-update
Add Yarn Package Directory:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
Install Yarn:
sudo apt-get update && sudo apt-get install yarn
Please note that the last command will upgrade yarn to latest version if package already installed.
For more info you can check the docs: yarn installation
If you already have yarn 1.x and you want to upgrade to yarn 2. You need to do something a bit different:
yarn set version berry
Where berry is the code name for yarn version 2. See this migration guide here for more info.
I tried at first
yarn policies set-version
Then it directed me to run
yarn set version stable
You should implement them in order, the first command will download your current yarn version and update .yarnrc after that running the second command will upgrade yarn successfully to the latest stable version
I tried all of the above solutions in Jenkins pipeline which needs the latest yarn.
Finally, this worked for me.
Run yarn policies set-version in the git repo
This will generate .yarn/releases/yarn-X.X.X.js file and .yarnrc file. Push both of these files in the Git repo.
Now build and all the yarn commands will use the yarn-X.X.X version.
Note: This is helpful when you don't have root access to npm install -g yarn.
npm i -g yarn
This should update your yarn version. Check version with yarn -v or yarn --version.
yarn policies set-version --rc
As per the yarn documentation to update yarn to latest version we should run the above command. Check version with yarn -v or yarn --version.
Ref : https://classic.yarnpkg.com/en/docs/cli/policies/#toc-policies-set-version
yarn policies set-version
Use the above command in powershell to upgrade your current yarn version to Latest.It will download the latest yarn release
yarn policies set-version
this upgraded my yarn version from 1.22.5 to 1.22.10
If You want to upgrade your yarn version from 1.22.5 to 1.22.10
yarn policies set-version
To upgrade to latest version of yarn, run the below command on your terminal.
"yarn set version latest -g"
This work for me to change yarn version 0.32 git to 1.22.5
https://www.codegrepper.com/code-examples/shell/yarn+0.32+git+ubuntu
Since you already have yarn installed and only want to upgrade/update. you can simply use
yarn self-update
Find ref here https://yarnpkg.com/en/docs/cli/self-update

yarn - What does #npm mean?

I know that running yarn add package#1.2.3 would install package v1.2.3.
I recently encountered this syntax: yarn add package#npm. What does #npm do? Is it a special sign for yarn or is it specific to that package (material-ui)?
I encountered #npm as a solution to include two versions of material-ui by aliasing the next version: yarn add material-ui-next#npm:material-ui#next
No real surprises, it is a directive to install a specific package from npm.
yarn add {package1} installs the specified package from the npm registry by default.
yarn add {package1}#npm:{package2} installs package2 from the npm registry and assigns package1 as its alias.
It makes no difference if a package named package1 exists in the npm registry, it will only download the package you've specified with the #npm directive.
From your question, it seems like you've already got a handle on this one.

yarn install ember-cli fails with incompatible node engine

My CircleCI builds started failing today and it looks like yarn is having trouble installing ember-cli. I tried locally and am suddenly getting the same error.
I recently upgraded to ember-cli 2.13.2, but I don't think that's related because builds were working after the upgrade.
Here's my console output:
~/code/my-app(master ✗) yarn global add ember-cli
yarn global v0.24.6
warning No license field
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
error core-object#3.1.2: The engine "node" is incompatible with this module. Expected version "=> ^4.0.0".
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.
What is your Node version? I've tried installing by yarn Ember CLI 1.13 project and it failed because CoreObject required versions between 4 and 7. I've downgraded Node from 8 to 7 and it worked.
I figured out my issue. I was using a Docker image that uses the latest version of node. When node updated to 8, my Circle builds started using that. I ended up creating my own image that is pegged at version 6 and using that on Circle instead.

Using Sails.js with yarn

When I run sails new myapp it generates a package.json file and a /node_modules directory. The sails docs say to cd in and run npm install to get up and running.
I've recently started using yarn and would like to use it to manage the additional dependencies I add to my sails app. However, when I run yarn init (what I think creates the yarn.lock file) it looks like it wants to create my package.json again. And it errors on the entry point question, saying Cannot convert object to primitive value.
Should I just stick to vanilla npm? Can Yarn and Sails play nicely in the sandbox together and share the toys?
In fact, $ yarn init (as well as $ npm init) will just initialize your package.json file by asking a few questions.
Here you don't need to regenerate your package.json but just install your node modules and generate a yarn.lock file to lock your modules versions. You can do this by using $ yarn install or just $ yarn.
You can skip $ yarn init as it does the exact same thing as $ npm init. $ yarn install actually creates the yarn.lock file. Unlike npm, yarn actually respects the engines property in a package.json file. If you run into this you can use $ yarn install --ignore-engines.