Search code examples
npmnpm-installpeer-dependencies

Ignore peer dependency check for single package in package.json


I try to exclude the package react-virtualized from the peer dependency checking of NPM 7. I know I could separately install that package with

npm install react-virtualized --legacy-peer-deps

...but my goal is to install all packages with npm install and this one shall not be checked for peer dependencies. Is that possible?

I would accept any answer that shows me how to manipulate the package.json so that a fresh npm install runs without peer dependency errors. I have the following package.json:

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-redux": "^7.2.4",
    "react-router": "^5.2.0",
    "react-router-dom": "^5.2.0",
    "react-beautiful-dnd": "^13.1.0",
    "react-device-detect": "^1.11.14",
    "react-markdown": "^7.0.0",
    "react-resize-detector": "^6.7.1",
    "react-virtualized": "^9.22.3"
  }  
}

Solution

  • With npm@>=8.3.0 use overrides in package.json:

    "overrides": {
      "react-virtualized": {
        "react": "$react",
        "react-dom": "$react-dom"
      }
    }
    

    See https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides