为什么 npm 安装说我有未被满足的依赖?

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 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

I must be confused about what exactly npm install does. 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?

转载于:https://stackoverflow.com/questions/20764881/why-does-npm-install-say-i-have-unmet-dependencies

15个回答

I believe it is because the dependency resolution is a bit broken, see https://github.com/isaacs/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

  2. Re-structure your 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.

The problem could be caused by npm's failure to download all the package due to timed-out or something else.

Note: You can also install the failed packages manually as well using npm install findup-sync@0.1.2.

Before running 'npm install', performing the following steps may help:

  • remove node_modules using rm -rf node_modules/
  • run npm cache clean

Why 'removing node_modules' sometimes is necessary? When a nested module fails to install during npm install, subsequent npm install won't detect those missing nested dependencies.

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. See

csdnceshi69
YaoRaoLov This worked perfectly for me after structuring the package.json, such that the top-level modules were listed down the order. In my case i was having trouble with react-interpolate-component and react-translate-component requiring a peer of react@^15.5.4r after I upgraded to react@16.2.0. Thanks for the help. I also did a cache clean before this.
2 年多之前 回复
csdnceshi61
derek5. I have deleted the node_modules, I have cleaned the cache and I have installed one by one all unmet dependencies and works, thank you very much.
接近 3 年之前 回复
csdnceshi59
ℙℕℤℝ Use rm -r node_modules NOT rm -rf node_modules
接近 3 年之前 回复
csdnceshi57
perhaps? why does ever other "solution" for npm include rm r node_modules? and why is it that this is really the only option in most of the cases? that's not quite how I figure a package manager should work like
3 年多之前 回复
weixin_41568110
七度&光 Go for the first suggestion: directly installing the missing module. Someone on NPM spent the time correctly implementing the error message. Do what it says.
3 年多之前 回复
csdnceshi58
Didn"t forge blindly just adding sudo to things that don't work right doesn't magically fix them, just means you don't know whats going on.
3 年多之前 回复
csdnceshi74
7*4 if npm cache clean doesn't work for access reasons, try sudo npm cache clean.
4 年多之前 回复
csdnceshi70
笑故挽风 removing 'node_modules', running 'npm cache clean', and then running 'npm install' fixed my issue. I had to run 'npm_install' three times, until i got all dependencies loaded without errors.
接近 6 年之前 回复
csdnceshi79
python小菜 Removing the node modules and cleaning the cache made it work for me.
接近 6 年之前 回复
csdnceshi54
hurriedly% geon raises another good point, if an npm install doesn't finish you'll get the same result. npm has been a bit flakey as of late, so sometimes modules simply fail to download, but re-running npm install in these case will sometimes fix itself.
大约 6 年之前 回复

I run npm list and installed all the packages listed as UNMET DEPENDENCY

For instance:

├── UNMET DEPENDENCY css-loader@^0.23.1
npm install css-loader@^0.23.1

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.

The command npm list gives 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 dependency were no longer noted as such.

To update npm, you should type npm install -g npm on MacOSX or Linux. On Windows, I found that re-downloading and re-running the nodejs installer was a more effective way to update npm.

weixin_41568126
乱世@小熊 I had the same problem with the npm version distributed in CentOS 7 repos. I installed latest npm version from node.js, and the problem disappeared, so I think your right, it can be an issue with an old version.
4 年多之前 回复

--dev installing devDependencies recursively (and its run forever..) how it can help to resolve the version differences?

You can try remove the node_moduls folder, then clean the npm cache and then run 'npm i' again

I encountered this problem when I was installing react packages and this worked for me: npm install --save <package causing this error>

In my case, the update of npm solved it.

sudo npm install -g npm

This solved it for me:

  1. Correct the version numbers in package.json, according to the errors;
  2. Remove node_modules (rm -rf node_modules);
  3. Rerun npm install.

Repeat these steps until there are no more errors.

It happened to me when the WIFI went down during an npm install. Removing node_modules and re-running npm install fixed it.

csdnceshi65
larry*wei Use rm -r node_modules NOT rm -rf node_modules to remove node_modules
接近 3 年之前 回复
csdnceshi53
Lotus@ rm -rf node_modules && npm cache clean && nvm use && npm i
3 年多之前 回复
weixin_41568131
10.24 The top level one.
接近 4 年之前 回复
csdnceshi73
喵-见缝插针 I'm confused as to which node_modules directory to remove? I have a similar problem with the error /usr/local/lib/node_modules/npm/node_modules/read-installed/node_modules/readdir-scoped-modules requires graceful-fs@'^4.1.2'
接近 4 年之前 回复
csdnceshi78
程序go Yeah doing npm cache clean was not enough for me, I had to remove the node_modules as well to get it to work after the networked failed during the "install".
5 年多之前 回复
csdnceshi51
旧行李 Reinstalling node probably isn't necessary, but between doing that, npm cache clean and removing node_modules, this advice worked for me.
大约 6 年之前 回复
weixin_41568184
叼花硬汉 and try npm cache clean.
大约 6 年之前 回复

I fixed the issue by using these command lines

  • $ rm -rf node_modules/
  • $ sudo npm update -g npm
  • $ npm install

It's done!

csdnceshi71
Memor.の HADDAD because rm -rf node_modules was not working for me and after over an hour of searching I found rm -r node_modules to work. I am on Windows 10. Also, make sure you run node as adminstrator.
接近 3 年之前 回复
csdnceshi53
Lotus@ can you explain why please ?
接近 3 年之前 回复
csdnceshi71
Memor.の Use rm -r node_modules NOT rm -rf node_modules
接近 3 年之前 回复
csdnceshi60
℡Wang Yan Do not use sudo with npm
接近 3 年之前 回复
csdnceshi53
Lotus@ I shared my experience, I did not know that I should be expert to share it, it's just a npm modules directory, it's not a sudo rm -vrfr / If you have an explanation it would be good to complete the answer and see your contribution or juste upvote the best answer it'll be great
大约 3 年之前 回复
csdnceshi61
derek5. might want to add "npm cache clean" in there too
3 年多之前 回复
csdnceshi57
perhaps? caveat: you shouldn't use sudo with npm, it's suggested instead to change the permissions or ownership of the directory npm wants to write too.
3 年多之前 回复
csdnceshi53
Lotus@ It worked for me and for other people, maybe you have an other problem. Try installing the module read-package-json globally sudo npm install -g read-package-json Or reinstall your npm
大约 4 年之前 回复
csdnceshi72
谁还没个明天 After running sudo npm update -g npm, my npm was rendered useless, any attempt to install anything results in "npm ERR! Cannot find module 'read-package-json'" im going to have to down vote this
4 年多之前 回复

The above answers didn't help me fully even after deleteting node_modules directory.

Below command helped me finally:

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

Note that this pulls node modules over an insecure HTTP connection.

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

csdnceshi79
python小菜 did you try the other answers also. You may have to run npm install multiple times and/or manually install some node packages one by one.
5 年多之前 回复
csdnceshi79
python小菜 nice to know :)
5 年多之前 回复
csdnceshi64
游.程 This helped me as well as my host was redirecting traffic.
5 年多之前 回复
共15条数据 1 尾页
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐