纱包不会在全球范围内升级(从NPM迁移之后) [英] Yarn package won't upgrade globally (after migrating from NPM)

查看:97
本文介绍了纱包不会在全球范围内升级(从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

Then, reinstalled yarn. 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!

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

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