weixin_41568196
撒拉嘿哟木头
采纳率40%
2013-12-24 17:49 阅读 925

为什么 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条回答 默认 最新

  • 已采纳
    csdnceshi52 妄徒之命 2013-12-24 18:37

    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

    点赞 25 评论 复制链接分享
  • csdnceshi78 程序go 2017-02-22 15:07

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

    点赞 9 评论 复制链接分享
  • weixin_41568184 叼花硬汉 2015-06-02 20:43

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

    点赞 7 评论 复制链接分享
  • csdnceshi67 bug^君 2014-04-17 11:13

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

    点赞 6 评论 复制链接分享
  • weixin_41568110 七度&光 2015-10-22 11:33

    I fixed the issue by using these command lines

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

    It's done!

    点赞 6 评论 复制链接分享
  • weixin_41568134 MAO-EYE 2016-08-17 02:24

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

    点赞 6 评论 复制链接分享
  • csdnceshi53 Lotus@ 2015-05-06 17:01

    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.

    点赞 5 评论 复制链接分享
  • weixin_41568134 MAO-EYE 2017-07-18 15:48

    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

    点赞 5 评论 复制链接分享
  • csdnceshi56 lrony* 2014-12-10 13: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

    点赞 3 评论 复制链接分享
  • weixin_41568126 乱世@小熊 2015-07-13 08:02

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

    点赞 3 评论 复制链接分享
  • csdnceshi60 ℡Wang Yan 2017-01-02 20:36

    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 评论 复制链接分享
  • csdnceshi56 lrony* 2016-07-07 18:17

    I had a similar issue while I was installing the React Native CLI. I wasn't sure which /node_modules directory I was supposed to remove after reading the answers here. I eventually just ran

    npm update -g

    and was able to install the package after that.

    点赞 1 评论 复制链接分享
  • csdnceshi55 ~Onlooker 2017-06-22 14:39

    In my case, the update of npm solved it.

    sudo npm install -g npm
    
    点赞 1 评论 复制链接分享
  • csdnceshi60 ℡Wang Yan 2017-06-01 17:56

    Take care about your angular version, if you work under angular 2.x.x so maybe you need to upgrade to angular 4.x.x

    Some dependencies needs angular 4

    Here is a tutorial for how to install angular 4 or update your project.

    点赞 评论 复制链接分享
  • csdnceshi78 程序go 2017-07-13 17:50

    Updating to 4.0.0

    Updating to 4 is as easy as updating your Angular dependencies to the latest version, and double checking if you want animations. This will work for most use cases.

    On Linux/Mac:

    npm install @angular/{common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-server,router,animations}@latest typescript@latest --save 
    

    On Windows:

    npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript@latest --save
    

    Then run whatever ng serve or npm start command you normally use, and everything should work.

    If you rely on Animations, import the new BrowserAnimationsModule from @angular/platform-browser/animations in your root NgModule. Without this, your code will compile and run, but animations will trigger an error. Imports from @angular/core were deprecated, use imports from the new package

    import { trigger, state, style, transition, animate } from '@angular/animations';.
    
    点赞 评论 复制链接分享

相关推荐