Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Npm peer dependency error

I am getting the npm peer dependency error repeatedly with npm install command . This is my package.json on which i have unmet peer dependency on react and webpack

    npm WARN [email protected] requires a peer of react@^0.14.0 but none was installed.
    npm WARN [email protected] requires a peer of webpack@1 || ^2.1.0-beta but none was installed.
    npm WARN [email protected] No repository field.
    npm WARN [email protected] license should be a valid SPDX license expression

{
  "name": "xxxxxxxxx",
  "version": "x.x.x",
  "description": "",
  "main": "index.js",
  "author": "",
  "license": "xxxxxxx",
  "dependencies": {
    "bootstrap": "^3.3.6",
    "fs": "0.0.2",
    "history": "^1.17.0",
    "immutable": "^3.8.1",
    "isomorphic-fetch": "^2.2.1",
    "lodash": "^4.11.1",
    "moment": "^2.13.0",
    "react": "^15.0.1",
    "react-autosuggest": "^3.7.3",
    "react-bootstrap": "^0.29.1",
    "react-datepicker": "^0.25.0",
    "react-dom": "^15.0.1",
    "react-redux": "^4.4.5",
    "react-router": "^2.3.0",
    "react-select": "^1.0.0-beta12",
    "redux": "^3.5.2"
  },
  "devDependencies": {
    "babel-core": "^6.7.7",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "bootstrap": "^3.3.6",
    "css-loader": "^0.23.1",
    "redux-devtools": "^3.2.0",
    "style-loader": "^0.13.1"
  }
}
like image 937
Hrittika Avatar asked May 12 '16 11:05

Hrittika


People also ask

Does npm install peer dependencies?

Current Behavior When running npm install , it does not install the peer dependencies automatically even if they are in the package-lock. json file. Instead it modifies the package-lock.


2 Answers

Well, firstly, those aren't errors, they're warnings. They won't actually stop your code from running, they're just there to give you a heads up if there's something wrong with your dependencies.

Effectively, peerDependencies are a way for packages to specify, "to use me, you should also have x version of y package installed". In your case, you have two issues:

  • That version of react-datepicker expects you to be using React 14, but you have React 15. If you update react-datepicker to the newest version, that one will be compatible with v15 - that said, there were very few breaking changes between those two version of React if I remember correctly, so if you're stuck using that particular version of the date picker for some reason, it should be safe to ignore that warning. Your mileage may vary, though.
  • babel-loader relies on Webpack, but you don't have any version of it installed. This does seem like a mistake on your part; run npm install webpack --save-dev and that should go away.

Hopefully with that context you'll be able to understand how to interpret those warnings in the future!

like image 165
Joe Clay Avatar answered Nov 08 '22 13:11

Joe Clay


There are warnings, not errors, but it's still worthwhile to fix.

  • react-datepicker: you should upgrade to the latest version (0.27.0), which declares react@^15.0.0 as a peer dependency.
  • babel-loader: the installation instructions explain that with npm@3 you need to declare peer dependencies (like webpack) explicitly in your package.json (using npm i webpack --save-dev).

The desktop-react warnings can be ignored.

like image 37
robertklep Avatar answered Nov 08 '22 15:11

robertklep