node.js 为什么 npm install 说我有未满足的依赖项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20764881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does npm install say I have unmet dependencies?
提问by Sean Mackesey
I have a node package. When I run npm installfrom 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 installdoes. 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?
我一定对究竟是npm install做什么感到困惑。如果它检测到依赖项,它不应该安装它吗?在什么情况下它会给我这样的错误消息,我该如何解决依赖关系?
采纳答案by dule
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 :
以下是可能的解决方案:
Manually need to install the top-level modules, containing unmet dependencies:
npm install [email protected]Re-structure your package.json. Place all the high-level modules (serves as a dependency for others modules) at the bottom.
Re-run the
npm installcommand.
需要手动安装顶级模块,包含未满足的依赖项:
npm install [email protected]重新构建您的 package.json。将所有高级模块(作为其他模块的依赖项)放在底部。
重新运行
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 [email protected].
注意:您也可以使用npm install [email protected].
Before running npm install, performing the following steps may help:
在运行之前npm install,执行以下步骤可能会有所帮助:
- remove node_modules using
rm -rf node_modules/ - run
npm cache clean
- 使用删除 node_modules
rm -rf node_modules/ - 跑
npm cache clean
Why 'removing node_modules' sometimes is necessary?
When a nested module fails to install during npm install, subsequent npm installwon't detect those missing nested dependencies.
为什么有时需要“删除 node_modules”?当嵌套模块在 期间安装失败时npm 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 installagain. See
如果是这种情况,有时删除那些丢失的嵌套模块的顶级依赖项并npm install再次运行就足够了。看
回答by geon
It happened to me when the WIFI went down during an npm install. Removing node_modulesand re-running npm installfixed it.
当 WIFI 在npm install. 删除node_modules并重新运行npm install修复它。
回答by zatamine
I fixed the issue by using these command lines
我使用这些命令行解决了这个问题
$ rm -rf node_modules/$ sudo npm update -g npm$ npm install
$ rm -rf node_modules/$ sudo npm update -g npm$ npm install
It's done!
完成!
回答by stephen
Upgrading NPM to the latest version can greatly help with this. 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.
将 NPM 升级到最新版本可以对此有很大帮助。上面dule 的回答是正确的说依赖管理有点坏,但似乎这主要是针对旧版本的npm。
The command npm listgives you a list of all installed node_modules. When I upgraded from version 1.4.2 to version 2.7.4, many modules that were previously flagged with WARN unmet dependencywere no longer noted as such.
该命令npm list为您提供了所有已安装node_modules. 当我从 1.4.2 版升级到 2.7.4 版时,许多以前标记WARN unmet dependency为 的模块不再被注明。
To update npm, you should type npm install -g npmon MacOSX or Linux. On Windows, I found that re-downloading and re-running the nodejs installer was a more effective way to update npm.
要更新 npm,您应该npm install -g npm在 MacOSX 或 Linux 上键入。在 Windows 上,我发现重新下载并重新运行 nodejs 安装程序是更新 npm 的更有效方法。
回答by Vinay Vemula
The above answers didn't help me fully even after deleteting node_modulesdirectory.
即使删除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 连接拉取节点模块。
回答by Akash
For every -- UNMET PEER DEPENDENCY, for ex. -- UNMET PEER DEPENDENCY [email protected], install that dependency with npm install --save [email protected]until you don't have any more UNMET DEPENDENCIES.
对于每个-- UNMET PEER DEPENDENCY,例如。-- UNMET PEER DEPENDENCY [email protected], 安装该依赖项,npm install --save [email protected]直到不再有UNMET DEPENDENCIES.
Good Luck.
祝你好运。
回答by achasinh
I run npm listand installed all the packages listed as UNMET DEPENDENCY
我运行npm list并安装了所有列为 UNMET DEPENDENCY 的软件包
For instance:
例如:
├── UNMET DEPENDENCY css-loader@^0.23.1npm install css-loader@^0.23.1
├── UNMET DEPENDENCY css-loader@^0.23.1npm install css-loader@^0.23.1
回答by user1585939
This solved it for me:
这为我解决了:
- Correct the version numbers in
package.json, according to the errors; - Remove
node_modules(rm -rf node_modules); - Rerun
npm install.
package.json根据错误更正 中的版本号;- 移除
node_modules(rm -rf node_modules); - 重新运行
npm install。
Repeat these steps until there are no more errors.
重复这些步骤,直到不再有错误。
回答by korp
I encountered this problem when I was installing react packages and this worked for me:
npm install --save <package causing this error>
我在安装 react 包时遇到了这个问题,这对我有用:
npm install --save <package causing this error>
回答by Marius
npm installwill install all the packages from npm-shrinkwrap.json, but might ignore packages in package.json, if they're not preset in the former.
npm install将安装 中的所有包npm-shrinkwrap.json,但可能会忽略 中的包package.json,如果它们没有在前者中预设。
If you're project has a npm-shrinkwrap.json, make sure you run npm shrinkwrapto regenerate it, each time you add add/remove/change package.json.
如果您的项目有一个npm-shrinkwrap.json,请确保npm shrinkwrap每次添加 add/remove/change 时都运行以重新生成它package.json。

