terminal defaults to old yarn version (lerna bootstrap) - yarnpkg

I don't think this is an issue specific to lerna, I actually think it is nvm related (though I commented out nvm from my .bash_profile to test that, without success).
I'm trying to lerna bootstrap but it keeps using (and failing) an older version (1.3.2) of yarn than what I'm running:
$ yarn -v
1.22.4
$ lerna bootstrap
info cli using local version of lerna
lerna notice cli v3.22.1
lerna info versioning independent
lerna info bootstrap root only
yarn install v1.3.2
error An unexpected error occurred: "patterns.map is not a function".
info If you think this is a bug, please open a bug report with the information provided in "yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
lerna ERR! yarn install --mutex network:42424 --non-interactive exited 1 in 'root'
lerna ERR! yarn install --mutex network:42424 --non-interactive exited 1 in 'root'
$ yarn -v
1.22.4

For me, this was happening in Ubuntu 20.04, and it solved with unistalling cmdtest:
sudo apt-get purge cmdtest

I rooted around in my filesystem and removed ~/.yarn and ~/node_modules/yarn and everything works now.

Upgrade yarn. I use brew so I used brew install yarn and it worked.

Related

Unable to install Yarn on Windows

I have Windows 10:
$ node -v
v16.14.0
$ npm -v
8.3.1
I run in terminal
$ npm install yarn -g
changed 1 package, and audited 2 packages in 666ms
found 0 vulnerabilities
but Yarn is not installed
$ yarn
C:\Users\G023911\AppData\Roaming\npm/node_modules/node/bin/node: line 1: This: command not found
I can't find anything helpful why it is not working for me.
You should only do that :
If Node.js >=16.10 (yarn >= 2.0) : corepack enable // else if Node.js <16.10 (yarn 1.0) : npm install --global yarn
Restart your terminal and your editor (all windows) if you using the terminal inside
Check installation with yarn --version but if you have npm it will works for sure (I have installed it many times on Windows and Linux this way & it's on the official 1.0 doc and official 2.0+ doc !

Command not found: corepack when installing Yarn on Node v17.0.1

I'm following the Yarn installation instructions on Yarn's website (https://yarnpkg.com/getting-started/install). Those instructions say that on Node version 16.10.0 and higher you can install Yarn by enabling corepack with the following command:
corepack enable
However, running that command returns:
zsh: command not found: corepack
I installed Node via Homebrew and node -v returns v17.0.1. I'm on an M1 Mac running Big Sur.
Because I had installed node via nvm (and I had installed nvm using Homebrew), the corepack command wasn't available. The fix that worked for me was to install corepack via homebrew by running:
brew install corepack
After installing corepack via homebrew, I was able to run the corepack enable command from the terminal and the yarn command became available as well.
Was facing a similar issue with node installed using asdf. Also using zsh and zsh asdf plugin.
Node version: 16.13.1
Ran corepack enable - and got
zsh: command not found: yarn
What solved for me:
asdf reshim nodejs
Also try to run
corepack prepare yarn#3.1.1 --activate
before reshim
I solved it like this:
From the https://github.com/nodejs/corepack docs
npm uninstall -g yarn pnpm
npm install -g corepack
Use with 'sudo' if you're using OSX

How do I upgrade yarn to a specific version

The Yarn documentation tells us how to upgrade to the latest version, but does not explain how to upgrade to a specific non-latest version.
I need a specific version to match our CI server.
How do I specify the version that I want?
run yarn policies set-version <version> from the project directory
https://classic.yarnpkg.com/en/docs/cli/policies/#toc-policies-set-version
As you can see in the documentation, you can provide a version to the curl-install command with the --version flag.
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]
In case you are using brew:
brew switch yarn [version]
Or maybe you installed it with npm as global package, then update like that:
npm install --global yarn#[version]
yarn set version [version.number] should work.
You can specify the yarn version using install in the following way:
Assuming you want version 1.7.0:
yarn upgrade v1.7.0
On Mac OSX 12.2.1 had following message when tried yarn upgrade v1.22.17
warning Your current version of Yarn is out of date. The latest version is "1.22.17", while you're on "1.22.4".
info To upgrade, run the following command:
$ brew upgrade yarn
success Saved 0 new dependencies.
So just did brew upgrade yarn and yarn --version returned 1.22.17

Why doesn't yarn updated when running upgrade?

I'm trying to use latest yarn version after upgrading it.
I've follow over https://yarnpkg.com/en/docs/install#mac-stable instructions, but yarn didn't really upgraded.
After running brew upgrade yarn:
$ brew upgrade yarn
Updating Homebrew...
Error: yarn 1.9.4 already installed
And after running yarn --version:
$ yarn --version
1.9.2
Is there any way to use the latest version?
Although the guide says that brew upgrade yarn should do it automatically..
There's a lengthy thread on Github regarding upgrades; here's what is suggested for HomeBrew:
brew upgrade yarn
brew link --overwrite yarn
Then try yarn -v
If that fails then you could:
First, uninstall brew's yarn:
brew uninstall yarn
Removing yarn binaries manually:
rm -f /usr/local/bin/yarnpkg
rm -f /usr/local/bin/yarn
Remove yarn cache:
rm -rf ${HOME}/.yarn
If you have the following in your .zshrc or .bash_profile, remove it:
export PATH="$PATH:`yarn global bin`"
Install via curl:
curl -o- -L https://yarnpkg.com/install.sh | bash
Make sure there is the following line in your .zshrc or .bash_profile:
export PATH="$HOME/.yarn/bin:$PATH"
↳ Github : yarn update discussion thread
If you installed yarn with npm in an nvm environment then you can just run npm -g upgrade yarn. To check that run which yarn -- if you see .nvm in the result of that, you are in an nvm environment.

replace yarn version v1.0.0 to v0.28.4

I currently used nightly builds to update my yarn and I'm using yarn v1.0.0-20170906.0822.
But it had a serious problem which is blocking deployment on Heroku.
So, I searched a way to migrate from v1.0.0xx to v0.28.4.
I tried to remove it using brew uninstall yarn however it failed to delete yarn so I can still v1.0.0xx shown when I hit yarn --version on the terminal.
I remember I installed yarn via brew, not npm.
Are there any other options to delete yarn and replace it with v0.28.4?
You can use the switch subcommand:
brew switch yarn 0.28.4

Resources