replace yarn version v1.0.0 to v0.28.4 - yarnpkg

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

Related

terminal defaults to old yarn version (lerna bootstrap)

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.

How do I change the version of yarn used by my system?

I am running Mac OS X 10.14.6 and I am trying to get the latest version of yarn installed and working on my system.
So I installed it with Homebrew, it tells me that I already have it installed on my system:
$ brew install yarn
Warning: yarn 1.21.1 is already installed and up-to-date
But when I do yarn --version, I get this:
$ yarn --version
[DEPRECATION] The trollop gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible.
Yarn v0.1.1 2011 Jesper Kjeldgaard
So I try to reinstall it and the following happens:
To reinstall 1.21.1, run `brew reinstall yarn`
Transmit-Live $ yarn --version
[DEPRECATION] The trollop gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible.
Yarn v0.1.1 2011 Jesper Kjeldgaard
Transmit-Live $ brew reinstall yarn
==> Reinstalling yarn
==> Downloading https://yarnpkg.com/downloads/1.21.1/yarn-v1.21.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/downloads/784c559ca8d97--yarn-v1.21.1.tar.gz
🍺 /usr/local/Cellar/yarn/1.21.1: 14 files, 5MB, built in 8 seconds
Transmit-Live $ yarn --version
[DEPRECATION] The trollop gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible.
Yarn v0.1.1 2011 Jesper Kjeldgaard
I have also tried brew switch and that doesn't work:
$ brew switch yarn 1.21.1
Cleaning /usr/local/Cellar/yarn/1.21.1
2 links created for /usr/local/Cellar/yarn/1.21.1
Transmit-Live $ yarn --version
[DEPRECATION] The trollop gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible.
Yarn v0.1.1 2011 Jesper Kjeldgaard
Edit 1
I even tried to do brew upgrade yarn and it is the same issue:
$ brew upgrade yarn
Warning: yarn 1.21.1 already installed
Transmit-Live $ yarn --version
[DEPRECATION] The trollop gem has been renamed to optimist and will no longer be supported. Please switch to optimist as soon as possible.
Yarn v0.1.1 2011 Jesper Kjeldgaard
Edit 2
Output of which yarn:
$ which yarn
/.rvm/gems/ruby-2.7.0#myapp/bin/yarn
How do I fix this?
Thanks.
I figured it out.
Basically what was happening is that I had two versions of yarn installed. One was a gem, and the other was the yarn executable.
So I simply ran gem uninstall yarn and it fixed it.
$ gem uninstall yarn
Remove executables:
yarn
in addition to the gem? [Yn] Y
Removing yarn
Successfully uninstalled yarn-0.1.1
Now when I do yarn --version it works properly.
$ yarn --version
1.21.1
You can upgrade a package with brew upgrade, so something like
brew upgrade yarn
You may need to get homebrew to update it's package list first, with brew update
[Edit]
In your case there is some confusion, the yarn package that brew installs is the javascript package manager, whereas the yarn you have on your path is the ruby gem. You can upgrade the latter with gem update yarn. If you want to use the JavaScript package manager, try modifying your path, or use the fully qualified path (something like /use/local/bin/yarn)

Incorrect integrity when fetching from the cache

When running yarn add --dev jest, I got error Incorrect integrity when fetching from the cache.
Full output:
tests (master)$ yarn add --dev jest
yarn add v1.19.0
info No lockfile found.
[1/4] Resolving packages...
warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > left-pad#1.3.0: use String.prototype.padStart()
[2/4] Fetching packages...
error Incorrect integrity when fetching from the cache
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
I tried removed node_modules, re-ran yarn install and yarn add --dev jest to no avail.
How do I fix this?
yarn cache clean
To fix this, run:
yarn cache clean
yarn add --dev jest
From the yarn cache documentation:
yarn cache clean [<module_name...>]
Running this command will clear the global cache. It will be populated again the next time yarn or yarn install is run. Additionally, you can specify one or more packages that you want to clean.
You can also see where the cache is with yarn cache dir.
yarn cache dir
Running yarn cache dir will print out the path where yarn’s global cache is currently stored.
Yarn cache clean did not help. We must downgrading yarn version on the server.
It turns out that the problem is associated with the use of private packages.
GitHub Yarnpkg - "Incorrect integrity when fetching from the cache" #7584
For anyone who is working with heroku and sees this error:
install heroku cli
login via heroku login
heroku plugins:install heroku-repo
heroku repo:purge_cache -a $YOURAPPNAME
then do a manual rebuild
Clean the cache and reinstall:
yarn cache clean
yarn install -f
You need to run these two commands before installing the package:
yarn config set unsafe-disable-integrity-migration false
yarn cache clean
Tried to upgrade yarn and it solved my problem. It may be due to the compatibility issue
yarn policies set-version
Will download the latest stable release
Reference : yarn docs https://yarnpkg.com/lang/en/docs/cli/policies/#toc-policies-set-version

Alias yarn to yarnpkg to avoid conflict with Hadoop Yarn

I have Yarn (package manager) already installed on my machine, but I now have to install Apache Hadoop. When I tried doing that with brew install hadoop, I got the error -
Error: Cannot install hadoop because conflicting formulae are installed.
yarn: because both install `yarn` binaries
Please `brew unlink yarn` before continuing.
Unlinking removes a formula's symlinks from /usr/local. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side-effects in the
resulting software.
This seems to be because Hadoop's Yarn conflicts with yarn from yarnpkg.
As mentioned here, they have no intention of renaming yarnpkg's yarn, but they have added yarnpkg as an alias to yarn.
This SO answer just mentions using yarnpkg instead of yarn to avoid the conflict, but there's no steps on how to do so.
I'd appreciate any help on how to setup yarnpkg alias so that I can install Hadoop alongside yarn.
I just solved it with unlinking and linking yarn again.
brew unlink yarn && brew link yarn
You can add an alias in .bashrc or .zshrc as follows
alias yarn='command yarnpkg'
I found that brew link yarn as mentioned in the answer above won't work.
I speculated whether that might link only the non-conflicting yarnpkg, but turns out it refused to link either, which seems quite fair.
Conceptually, (with yarn package manager unlinked) what you can do is add an alias to your .bash_profile like alias yarnpkg /usr/local/Cellar/yarn/1.22.0/bin/yarnpkg
Note that won't be robust to when you brew upgrade yarn to a new version.
Also, adding that directory to your path is not a good idea, because that makes ambiguous the fact you have two separate programs called yarn installed.
An alternative to adding the bash alias is to just add the single, non-conflicting symlink manually in the same way brew link would do if it didn't refuse, as mentioned above:
ln -s /usr/local/Cellar/yarn/1.22.0/bin/yarnpkg /usr/local/bin/yarnpkg
It remains to be seen what happens when yarnpkg is updated, so keep an eye out for that. Since yarnpkg is not, apparently, symlinked by brew (except we sneakily added one), if brew doesn't update that symlink to point to the new version, then yarnpkg will stop working when you brew upgrade yarn, unless you repeat the manual ln as above pointing to the new version.
Update
Just tried it. Brew actually refuses to upgrade yarn, giving the reason that it conflicts with hadoop. So, we can brew unlink hadoop, as it suggests, then brew upgrade yarn.
Then, brew unlink yarn, brew link hadoop (hadoop has far more needed links than yarnpkg), then, finally, recreate the yarnpkg symlink with new version like so: /usr/local/Cellar/yarn/1.22.1/bin/yarnpkg
Quite long winded, but works fine.
Here is an easier way to solve this issue:
install hadoop using HomeBrew
manually install yarn using tarball
Step by step guide if already installed conflicting yarn and hadoop using Homebrew:
Clean up conflict in Homebrew and Install Hadoop
brew uninstall yarn
brew uninstall hadoop
brew install hadoop
brew link hadoop(optional if hadoop is already installed by HomeBrew but not linked)
Instal yarn using tarball
brew install wget (if does not have wget)
cd /opt
wget https://yarnpkg.com/latest.tar.gz (use sudo if permission denied)
tar zvxf latest.tar.gz (use sudo if permission denied)
open any of the following files ~/.profile, ~/.bash_profile, ~/.bashrc, ~/.zshrc in the code editor to add yarn to the path
Add these two lines
export PATH="$PATH:/opt/yarn-[version]/bin"
export PATH="$PATH:`yarn global bin`"
see more on the yarn official doc

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

Resources