423

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?

Damjan Pavlica
  • 31,277
  • 10
  • 71
  • 76
Sean Mackesey
  • 10,701
  • 11
  • 40
  • 66

17 Answers17

415

I believe it is because the dependency resolution is a bit broken, see 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

  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

Liam
  • 27,717
  • 28
  • 128
  • 190
dule
  • 17,798
  • 4
  • 39
  • 38
  • 1
    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. – dule Apr 17 '14 at 21:20
  • 22
    Removing the node modules and cleaning the cache made it work for me. – MarkoHiel Aug 12 '14 at 07:20
  • 4
    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. – hendrix Aug 20 '14 at 10:37
  • 2
    if `npm cache clean` doesn't work for access reasons, try `sudo npm cache clean`. – Soroush Aug 31 '15 at 11:50
  • 13
    @Soroush 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. –  Sep 20 '16 at 08:45
  • 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. – Hal50000 Nov 05 '16 at 16:17
  • 5
    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 – phil294 Feb 02 '17 at 16:04
  • Use rm -r node_modules NOT rm -rf node_modules – BinaryJoe01 Jul 10 '17 at 22:50
  • 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. – AfroChase Jul 14 '17 at 19:34
  • 1
    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. – Gautam Feb 15 '18 at 07:12
  • i had the problem of having unmet dependencies showing up in `npm list`, even after uninstalling nodejs package and removing all node related folders. I was able to resolve those warnings using the command `npm update`. – GlabbichRulz Mar 14 '20 at 12:02
89

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

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
geon
  • 8,128
  • 3
  • 34
  • 41
  • 27
    and try `npm cache clean`. – ijse May 09 '14 at 12:29
  • 5
    Reinstalling node probably isn't necessary, but between doing that, `npm cache clean` and removing `node_modules`, this advice worked for me. – RichLitt May 26 '14 at 18:26
  • @RichLitt, 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". – Mark Tomlin Nov 19 '14 at 16:31
  • 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'` – wuliwong Jul 06 '16 at 22:39
  • 1
    @wuliwong The top level one. – geon Jul 09 '16 at 18:26
  • `rm -rf node_modules && npm cache clean && nvm use && npm i` – Aamir Afridi Nov 28 '16 at 15:12
  • Use rm -r node_modules NOT rm -rf node_modules to remove node_modules – BinaryJoe01 Jul 10 '17 at 22:51
33

I fixed the issue by using these command lines

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

It's done!

zatamine
  • 3,458
  • 3
  • 25
  • 33
  • 5
    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 – MichaelB Feb 22 '16 at 05:23
  • 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 – zatamine Feb 27 '16 at 13:23
  • 10
    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. – Sgnl Sep 08 '16 at 23:44
  • 1
    might want to add "npm cache clean" in there too – Alexander Mills Oct 12 '16 at 05:43
  • 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 – zatamine May 24 '17 at 22:56
  • 2
    Do not use `sudo` with npm – Grant Jun 30 '17 at 16:00
  • Use rm -r node_modules NOT rm -rf node_modules – BinaryJoe01 Jul 10 '17 at 22:50
  • @BinaryJoe01 can you explain why please ? – zatamine Jul 15 '17 at 11:02
  • @Amine 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.* – BinaryJoe01 Jul 18 '17 at 22:49
12

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.

S. Dixon
  • 842
  • 1
  • 12
  • 26
  • 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. – Elouan Keryell-Even Jan 04 '16 at 12:59
11

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

Community
  • 1
  • 1
Vinay Vemula
  • 3,855
  • 1
  • 21
  • 24
6

For every -- UNMET PEER DEPENDENCY, for ex. -- UNMET PEER DEPENDENCY rxjs@5.0.0-rc.2, install that dependency with npm install --save rxjs@5.0.0-rc.2 until you don't have any more UNMET DEPENDENCIES.

Good Luck.

Aakash
  • 21,375
  • 7
  • 100
  • 81
  • 1
    Leaves me with the same errors including a new one: `ERR! code 1` – Wouter Vanherck Mar 29 '17 at 10:14
  • 1
    @WouterVanherck can you please try `rm -rf node_modules`, then `npm cache clean` and `npm install`. If it still doesn't work, I suggest you to again `rm -rf node_modules`, then `npm i -g yarn` and then `yarn install`. [Yarn](https://yarnpkg.com/en/) is quite good to manage `node_modules`. Good Luck. – Aakash Mar 29 '17 at 23:40
  • 1
    Yes, is what ```peerDependencies``` is for. To push you to a conscious choice of the version. – Kamafeather Jul 17 '18 at 01:52
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

achasinh
  • 530
  • 8
  • 17
2

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.

wuliwong
  • 4,238
  • 9
  • 41
  • 69
2

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.

Julien Lopez
  • 1,794
  • 5
  • 18
  • 24
1

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.

John Doe
  • 2,173
  • 1
  • 21
  • 12
1

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

arielhad
  • 1,753
  • 15
  • 12
1

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

Uberbrady
  • 482
  • 5
  • 9
1

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

korp
  • 13
  • 5
1

In my case, the update of npm solved it.

sudo npm install -g npm
Marcelo Gumiero
  • 1,849
  • 2
  • 14
  • 14
1

npm install will install all the packages from npm-shrinkwrap.json, but might ignore packages in package.json, if they're not preset in the former.

If you're project has a npm-shrinkwrap.json, make sure you run npm shrinkwrap to regenerate it, each time you add add/remove/change package.json.

Marius
  • 3,589
  • 3
  • 27
  • 30
0

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.

Terai
  • 311
  • 1
  • 4
  • 13
0

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';.
Machavity
  • 30,841
  • 27
  • 92
  • 100