Why does npm install say I have unmet dependencies

2019-01-01 11:48发布

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?

17条回答
只若初见
2楼-- · 2019-01-01 12:10

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.

查看更多
闭嘴吧你
3楼-- · 2019-01-01 12:10

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

查看更多
墨雨无痕
4楼-- · 2019-01-01 12:22

I was trying to work on an automated deployment system that runs npm install, so a lot of these solutions wouldn't work for me in an automated fasion. I wasn't in a position to go deleting/re-creating node_modules/ nor could I easily change Node.js versions.

So I ended up running npm shrinkwrap - adding the npm-shrinkwrap.json file to my deployment bundle, and running installs from there. That fixed the problem for me; with the shrinkwrap file as a 'helper', npm seemed to be able to find the right packages and get them installed for me. (Shrinkwrap has other features as well, but this was what I needed it for in this particular case).

查看更多
其实,你不懂
5楼-- · 2019-01-01 12:23

In my case, the update of npm solved it.

sudo npm install -g npm
查看更多
十年一品温如言
6楼-- · 2019-01-01 12:24

I fixed the issue by using these command lines

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

It's done!

查看更多
宁负流年不负卿
7楼-- · 2019-01-01 12:25

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

查看更多
登录 后发表回答