Ignore peer dependency check for single package in package.json
Asked Answered
H

2

14

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"
  }  
}
Holmgren answered 19/8, 2021 at 13:17 Comment(1)
Why do you want to use npm install and not include any flags? (Asking because it affects the viability of potential solutions, like requiring a particular version of npm.)Ineffable
A
27

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

Aldo answered 8/12, 2022 at 18:19 Comment(0)
I
5

There isn't a way to do that within your own package.json as far as I am aware. The change would need to happen in the package.json for the react-virtualized package. Perhaps one of these alternatives will work for you:

  1. Set legacy-peer-deps in a .npmrc file for your project. This won't work if people are installing your project via npm but if your project is cloned from a git repository or otherwise downloaded, and then people run npm install from there, including a .npmrc in the project should work.

  2. Require using npm@6 which will be more lenient about peer dependency checks. You can specify the npm version in the "engines" field in your package.json.

  3. Install react-virtualized from GitHub. The master branch (and, as of this writing, unfortunately only the master branch) has the d36509817ac44 commit which added react@17 and react-dom@17 as acceptable peer dependencies. Because this code is not in any release yet, you may be getting a version of the module that is unstable. To do this: npm install git+https://github.com/bvaughn/react-virtualized.git

  4. Use react@16 and react-dom@16 instead of @17 for each.

Ineffable answered 19/8, 2021 at 13:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.