为什么npm install说我有未满足的依赖关系?

本文翻译自:Why does npm install say I have unmet dependencies?

I have a node package. 我有一个节点包。 When I run npm install from the package root, it installs a bunch of things, but then prints several error messages that look like this: 当我从软件包根目录运行npm install ,它会安装很多东西,但是会打印出一些如下所示的错误消息:

npm WARN unmet dependency /Users/seanmackesey/google_drive/code/explore/generator/node_modules/findup-sync/node_modules/glob requires graceful-fs@'~1.2.0' but will load npm WARN未满足依赖项/ Users / seanmackesey / google_drive / code / explore / generator / node_modules / findup-sync / node_modules / glob需要graceful-fs@'~1.2.0'但会加载

I must be confused about what exactly npm install does. 我对npm install到底能做什么感到困惑。 If it detects a dependency, shouldn't it install it? 如果它检测到依赖性,是否应该安装它? Under what conditions does it give me error messages like this, and how can I resolve the dependencies? 在什么情况下它会给我这样的错误消息,以及如何解决依赖关系?


#1楼

参考:https://stackoom.com/question/1P7tR/为什么npm-install说我有未满足的依赖关系


#2楼

I believe it is because the dependency resolution is a bit broken, see https://github.com/npm/npm/issues/1341#issuecomment-20634338 我相信这是因为依赖项解析有点中断,请参阅https://github.com/npm/npm/issues/1341#issuecomment-20634338

Following are the possible solution : 以下是可能的解决方案:

  1. Manually need to install the top-level modules, containing unmet dependencies: npm install findup-sync@0.1.2 手动需要安装包含未满足的依赖项的顶级模块: npm install findup-sync@0.1.2

  2. Re-structure your package.json. 重新组织package.json。 Place all the high-level modules (serves as a dependency for others modules) at the bottom. 将所有高级模块(作为其他模块的依赖项)放在底部。

  3. Re-run the npm install command. 重新运行npm install命令。

The problem could be caused by npm's failure to download all the package due to timed-out or something else. 该问题可能是由于超时或其他原因导致npm无法下载所有软件包所致。

Note: You can also install the failed packages manually as well using npm install findup-sync@0.1.2 . 注意:您也可以使用npm install findup-sync@0.1.2手动安装失败的软件包。

Before running npm install , performing the following steps may help: 在运行npm install之前,执行以下步骤可能会有所帮助:

  • remove node_modules using rm -rf node_modules/ 使用rm -rf node_modules/删除node_modules
  • run npm cache clean 运行npm cache clean

Why 'removing node_modules' sometimes is necessary? 为什么有时需要“删除node_modules”? When a nested module fails to install during npm install , subsequent npm install won't detect those missing nested dependencies. 当嵌套模块在npm install install期间无法安装时,后续的npm install将不会检测到那些缺少的嵌套依赖项。

If that's the case, sometimes it's sufficient to remove the top-level dependency of those missing nested modules, and running npm install again. 如果是这种情况,有时只需删除那些缺少的嵌套模块的顶级依赖关系,然后再次运行npm install See 看到


#3楼

It happened to me when the WIFI went down during an npm install . npm install过程中WIFI npm install时,这件事发生在我身上。 Removing node_modules and re-running npm install fixed it. 删除node_modules并重新运行npm install修复它。


#4楼

The above answers didn't help me fully even after deleteting node_modules directory. 上面的答案即使删除了node_modules目录也没有完全帮助我。

Below command helped me finally: 下面的命令终于帮助了我:

npm config set registry http://registry.npmjs.org/

Note that this pulls node modules over an insecure HTTP connection. 请注意,这会通过不安全的HTTP连接拉动节点模块。

Src: https://stackoverflow.com/a/13119867/4082503 Src: https//stackoverflow.com/a/13119867/4082503


#5楼

Upgrading NPM to the latest version can greatly help with this. 将NPM升级到最新版本可以大大帮助您。 dule's answer above is right to say that dependency management is a bit broken, but it seems that this is mainly for older versions of npm. dule上面的回答是正确的,它说依赖性管理有些问题,但这似乎主要是针对旧版本的npm。

The command npm list gives you a list of all installed node_modules . 命令npm list为您提供所有已安装的node_modules的列表。 When I upgraded from version 1.4.2 to version 2.7.4, many modules that were previously flagged with WARN unmet dependency were no longer noted as such. 当我从1.4.2版升级到2.7.4版时,以前标记为WARN unmet dependency项的许多模块不再被这样指出。

To update npm, you should type npm install -g npm on MacOSX or Linux. 要更新npm,应在MacOSX或Linux上键入npm install -g npm On Windows, I found that re-downloading and re-running the nodejs installer was a more effective way to update npm. 在Windows上,我发现重新下载并重新运行nodejs安装程序是更新npm的更有效方法。


#6楼

Some thing in the similar vein, I would add one other step. 类似的事情,我会再增加一个步骤。

Note that on npm version > 1.4.9, 'npm install' does install devDependencies. 请注意,在npm版本> 1.4.9上,“ npm install”确实会安装devDependencies。 First try removing existing modules and cache: 首先尝试删除现有模块和缓存:

remove node_modules $ rm -rf node_modules/
run $ npm cache clean

Then try: 然后尝试:

npm install --dev
npm update --dev

This at least will resolve the recursive dependency resolution. 这至少将解决递归依赖性解析。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值