Yarn 包不会全局升级(从 NPM 迁移后) [英] Yarn package won't upgrade globally (after migrating from NPM)

查看:131
本文介绍了Yarn 包不会全局升级(从 NPM 迁移后)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行 yarn global upgrade generator-jhipster 但即使它看起来正在运行并安装最新版本,当我运行 yo jhipster 它仍然是旧版本,会提示我运行 yarn global upgrade generator-jhipster

I was trying to run yarn global upgrade generator-jhipster but even though it seemed like it was working and installing the latest version, when I would run yo jhipster It would still be on an old version and would prompt me to run yarn global upgrade generator-jhipster

我在 OSX (Mac) 上运行

I was running on OSX (Mac)

我最近才开始使用 Yarn.我之前使用过 NPM,但卸载了 NPM.

I had just recently started using Yarn. I was previously using NPM but uninstalled NPM.

$HOME/.config/yarn/global/node_modules/.bin 在我的路径中,所以这不是问题.

$HOME/.config/yarn/global/node_modules/.bin was in my path, so that wasn't the issue.

推荐答案

当我从 NPM 切换到 Yarn 时,我在卸载 NPM 之前没有删除 NPM 安装的包.因此,当通过 Yarn 添加全局包时,符号链接仍然与 NPM 安装相关联.这导致我在通过 Yarn 全局升级/添加包时遇到问题,因为它没有指向 Yarn 管理的新版本.

When I switched over from NPM to Yarn, I did not remove the packages installed by NPM before uninstalling NPM. So, when adding global packages via Yarn, the symlinks were still associated with the NPM installations. This caused me to have issues globally upgrading/adding the packages through Yarn, since it wasn't pointing to the new versions managed by Yarn.

(我通过 Homebrew 安装了 Node 和 NPM,这就是我最终重新安装 NPM 的方式:)

(I had installed Node and NPM via Homebrew and this is how I ended up reinstalling NPM:)

brew uninstall --force yarn
brew uninstall --force node
brew install node

然后我删除了所有 NPM 的全局模块,因为我现在想专门使用 Yarn.(在执行此操作之前,请确保您确实希望删除所有这些!您可能想要运行 npm list -g --depth=0 以查看 NPM 为您管理的内容,以便您可以使用 Yarn 重新安装)(这不适用于 Windows,对于 Windows 版本,请参阅 Ollie Bennett 的回答

Then I removed all of NPM's global modules since I wanted to exclusively use Yarn now. (Make sure you really want all of these removed before you do this! You might want to run npm list -g --depth=0 to see what NPM was managing for you, so you can reinstall with Yarn) (This does not work on Windows, for a Windows version, see Ollie Bennett's Answer

npm ls -gp --depth=0 | awk -F/ '/node_modules/ && !/\/npm$/ {print $NF}' | xargs npm -g rm

这是它的工作原理:摘自 Kai Sternad 的回答

  • npm ls -gp --depth=0 列出所有全局顶级模块(请参阅 ls 的 cli 文档)
  • awk -F/'/node_modules/&&!/\/npm$/{print $NF}' 打印所有实际上不是 npm 本身的模块(不以/npm 结尾)
  • xargs npm -g rm 全局删除来自前一个管道的所有模块
  • npm ls -gp --depth=0 lists all global top level modules (see the cli documentation for ls)
  • awk -F/ '/node_modules/ && !/\/npm$/ {print $NF}' prints all modules that are not actually npm itself (does not end with /npm)
  • xargs npm -g rm removes all modules globally that come over the previous pipe

然后,重新安装纱线.brew install yarn

确保您的路径中有 $HOME/.config/yarn/global/node_modules/.bin.(参见纱线路径设置

Be sure you have $HOME/.config/yarn/global/node_modules/.bin in your path. (see Yarn Path Setup

在 Mac 或 Linux 上:

On Mac or Linux:

export PATH="$PATH:`yarn global bin`:$HOME/.config/yarn/global/node_modules/.bin"

然后安装 yo 和 generator-jhipster(我已经通过 Yarn 删除了它们)(参见 安装 JHipster)

Then installed yo and generator-jhipster (I had already removed these via Yarn) (see Installing JHipster)

yarn global add yo
yarn global add generator-jhipster

添加终于全局更新到最新版本了!

Add it was finally globally updated to the latest version!

这篇关于Yarn 包不会全局升级(从 NPM 迁移后)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆