Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Peer dependency errors from npm even though actual dependency version correctly follows semver

I'm getting npm ERR! invalid errors when I try npm ls or npm install, and it seems like npm is incorrectly thinking peers have incompatible versions. A good example (I get several of these at a time):

npm WARN unmet dependency /MYLOCALPROJECTDIRECTORY/node_modules/grunt-contrib-imagemin/node_modules/imagemin/node_modules/imagemin-gifsicle requires image-type@'^0.1.1' but will load
npm WARN unmet dependency /MYLOCALPROJECTDIRECTORY/node_modules/grunt-contrib-imagemin/node_modules/imagemin/node_modules/image-type,
npm WARN unmet dependency which is version 0.1.4

According to the rules of semver, the caret "^" operator should match a requirement of ^0.1.1 with an actual dependency of version 0.1.4 just fine.

I've installed Node v0.10.30 with npm v1.4.23 using Homebrew (both the latest stables), running OS X Mountain Lion. I'd appreciate tips on finding how to reliably reproduce this - last time I totally uninstalled/reinstalled Node and npm, same local npm modules and everything, and could not find the error again. Came back to work the next day, tried to install some grunt plugin, and ran into all these errors again.

like image 369
iono Avatar asked Aug 06 '14 07:08

iono


People also ask

How do I resolve npm dependency errors?

The easiest way to fix the issue is to pass an additional parameter –legacy-peer-deps to npm install. The --legacy-peer-deps tells the npm to ignore the peer dependencies and continue the installation of the package.

How do you resolve peer dependencies?

Peer dependencies are resolved from dependencies installed higher in the dependency graph, since they share the same version as their parent. That means that if [email protected] has two peers ( bar@^1 and baz@^1 ) then it might have multiple different sets of dependencies in the same project.

Does npm automatically install peer dependencies?

With npm version 4 through to 6, a warning is issued when you run npm install to remind you to install the peer dependencies. Prior to version 4, npm automatically included peer dependencies if they weren't explicitly included.

What is npm Peer dependency?

Peer Dependencies are used to specify that our package is compatible with a specific version of an npm package. Good examples are Angular and React. To add a Peer Dependency you actually need to manually modify your package.json file.


1 Answers

If you happen to reproduce it, I bet you can solve it by removing the node_modules folder, cleaning the cache and reinstalling:

rm -rf ./node_modules
npm cache clean
npm install

I know this is not an actual answer, but I guess it's better than uninstalling/reinstalling node/npm.

like image 141
mostruash Avatar answered Oct 13 '22 08:10

mostruash