将我的 npm 从版本 6 升级到版本 7(节点版本为 10)后,我无法为某些项目安装依赖项

Moh*_*r Z 7 node.js npm package.json package-lock.json

我曾节点版本10安装在我的系统,从版本6升级我的NPM至7版本我不能安装依赖后,和我得到的错误,所以我只好我的节点降级到6,(包括npm cinpm i不及格)我正在测试的项目是这样的:

https://github.com/Giveth/feathers-giveth

错误是这样的:

npm ERR! code 128
npm ERR! git dep preparation failed
npm ERR! command /Users/username/.nvm/versions/node/v10.23.0/bin/node /Users/username/.nvm/versions/node/v10.23.0/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/Users/username/.npm/_cacache --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm ERR! code 128
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command git clone --mirror -q ssh://git@github.com/gulpjs/gulp.git /Users/renjer/.npm/_cacache/_cacache/tmp/git-clone-dfb83c15/.git
npm ERR! npm ERR! fatal: destination path '/Users/username/.npm/_cacache/_cacache/tmp/git-clone-dfb83c15/.git' already exists and is not an empty directory.
npm ERR!
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /Users/username/.npm/_cacache/_logs/2021-02-18T16_18_35_855Z-debug.log

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/username/.npm/_logs/2021-02-18T16_20_15_536Z-debug.log
Run Code Online (Sandbox Code Playgroud)

小智 1

这个问题通常会发生,因为如果你只升级系统的node版本,有一些包和依赖项是根据该版本安装的。

这是一个手动过程,但您必须根据该版本安装软件包。

例如 (package.json):在您的 Node 6 版本中,您有一些包:

"xyz":^1.2.3
Run Code Online (Sandbox Code Playgroud)

该软件包已安装,其依赖项可与节点 6 一起使用,从 package.json 中手动删除该软件包并手动安装,如下所示

npm install xyz
Run Code Online (Sandbox Code Playgroud)

然后您可能会注意到版本升级,例如:

"xyz":^4.5.6
Run Code Online (Sandbox Code Playgroud)

对您的每个包都这样做,您的问题可能就会消失。这就是我用来解决这个问题的方法。

您还可以将所有软件包升级到最新版本,但是......如果您有很多软件包并且有人不工作,您将不知道哪个软件包出现故障,并且您将单独检查它。

也许(在撰写此答案时)如果您使用的是 Node 10,则最新软件包的版本也将无法工作,因为该版本可以修复为与 Node 16(目前的 LTS(长期支持)版本)一起使用写这个答案)。

如果您还没有这样做,我建议您不断地将系统升级到某个尚未弃用的 LTS 版本。