##What is the problem?
├─┬ grunt@0.4.5
│ ├─┬ findup-sync@0.1.3
│ │ └── lodash@2.4.1
│ ├─┬ grunt-legacy-log@0.1.1
│ │ └── lodash@2.4.1
│ └── lodash@0.9.2
├─┬ grunt-contrib-watch@0.6.1
│ └─┬ gaze@0.5.1
│ └─┬ globule@0.1.0
│ └── lodash@1.0.1
└── lodash@2.4.1
Then I wanna to install the "lodash" with version 3.10.1, so I run the command "npm install [email protected]" and it happens
npm WARN package.json EuroSports@0.1.0 No license field.
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/cheerio requires lodash@'~2.4.1' but will load
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/lodash,
npm WARN unmet dependency which is version 3.10.1
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/grunt-contrib-less requires lodash@'^2.4.1' but will load
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/lodash,
npm WARN unmet dependency which is version 3.10.1
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/grunt-contrib-uglify requires lodash@'^2.4.1' but will load
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/lodash,
npm WARN unmet dependency which is version 3.10.1
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/grunt-contrib-watch requires lodash@'~2.4.1' but will load
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/lodash,
npm WARN unmet dependency which is version 3.10.1
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/grunt-cli/node_modules/findup-sync requires lodash@'~2.4.1' but will load
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/lodash,
npm WARN unmet dependency which is version 3.10.1
lodash@3.10.1 node_modules/lodash
The installation is wrong, I can't install [email protected] at all, when I enter command to check version of lodash (npm list lodash), it shows me:
├─┬ grunt@0.4.5
│ ├─┬ findup-sync@0.1.3
│ │ └── lodash@2.4.1
│ ├─┬ grunt-legacy-log@0.1.1
│ │ └── lodash@2.4.1
│ └── lodash@0.9.2
├─┬ grunt-contrib-watch@0.6.1
│ └─┬ gaze@0.5.1
│ └─┬ globule@0.1.0
│ └── lodash@1.0.1
└── lodash@3.10.1 invalid
npm ERR! invalid: lodash@3.10.1 /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/lodash
Of course I can't call any new API of lodash at version 3.10.1
##Why it happened?
After few hours crying and screaming, I finally understand why.
Here is the reason:
-
I misunderstood how peerDependences and "require" work.
Assume that we have package A, it depends on another package B. In the app, we also use package B, so there will be 2 cases: -
If you don't define the the version of Package in app package.json, it will share the package B in /node_module/packageB
-
If the versions are different, the npm will install 2 difference versions, one in the packageA/node_modules/packageB and another in app root folder /node_module/packageB.
##How to fix it?
Uninstall and reinstall the "unmet dependency" from top to bottom.
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/cheerio requires lodash@'~2.4.1' but will load
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/lodash,
npm WARN unmet dependency which is version 3.10.1
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/grunt-contrib-less requires lodash@'^2.4.1' but will load
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/lodash,
npm WARN unmet dependency which is version 3.10.1
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/grunt-contrib-uglify requires lodash@'^2.4.1' but will load
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/lodash,
npm WARN unmet dependency which is version 3.10.1
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/grunt-contrib-watch requires lodash@'~2.4.1' but will load
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/lodash,
npm WARN unmet dependency which is version 3.10.1
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/grunt-cli/node_modules/findup-sync requires lodash@'~2.4.1' but will load
npm WARN unmet dependency /Users/khanghoangtrieu/Documents/2359media/EuroSports/node_modules/lodash,
npm WARN unmet dependency which is version 3.10.1
You just uninstall and install the "cheerio", "grunt-contrib-less", "grunt-contrib-uglify", "grunt-contrib-watch", "findup-sync" and finally "lodash".
Hope it helps.