QC-L/blog

关于 yarn 的更新

QC-L opened this issue · 0 comments

QC-L commented

官方给出的建议是,不使用 yarn/npm 管理 yarn,因此采用的是 brew 的管理方式。(stackoverflow 的讨论

方式一:

更新 yarn,先移除 yarn,重新下载

brew remove yarn
brew install yarn --ignore-dependencies

按如上操作,会出现以下警告⚠️

Warning: --ignore-dependencies is an unsupported Homebrew developer flag!
Adjust your PATH to put any preferred versions of applications earlier in the
PATH rather than using this unsupported flag!

并且会报出如下错误

Error: An exception occurred within a child process:
  RuntimeError: /usr/local/opt/node not present or broken
Please reinstall node. Sorry :(

其原因是,找不到 yarn 的依赖项(node)。
我们需要给对应的文件夹创建一个 node 的软链:

mkdir /usr/local/opt/node
ln -s ~/.nvm/versions/node/v12.16.1/bin/node /usr/local/opt/node 

再重新执行 install 即可:

brew install yarn

然后就是开心的

==> Downloading https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/49970642/487f6380-61e3-11ea-8294-0d743f488e
######################################################################## 100.0%
🍺  /usr/local/Cellar/yarn/1.22.4: 14 files, 5MB, built in 15 seconds

方式二:

brew upgrade yarn

参考资料:

yarnpkg/website#913
https://classic.yarnpkg.com/en/docs/usage
yarnpkg/yarn#7306