pnpm icon indicating copy to clipboard operation
pnpm copied to clipboard

pnpm showing error when peerDependenciesMeta.*.optional

Open lucas-labs opened this issue 3 years ago • 3 comments

pnpm version: 7.8.0

We have an internal library that has 3 optional peer dependencies, marked with peerDependenciesMeta.*.optional = true. We are migrating to pnpm from yarn but pnpm throws a "missing peer dependencies" error when installing this library. Yarn and npm doesn't show any errors.

Code to reproduce the issue:

package.json of the library that's being installed:

{
  "name": "@lucas-labs/nest-utils",
  "version": "0.1.10",
  "dependencies": {
    "tslib": "2.3.0"
  },
  "peerDependencies": {
    "@lucas-labs/common": "^0.1.2",
    "@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.0.0",
    "@nestjs/core": "^7.0.0 || ^8.0.0 || ^9.0.0",
    "@nestjs/bullmq": "^0.1.0",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.4.0",
    "bullmq": "^1.82.2",
    "rotating-file-stream": "^2.1.6"
  },
  "peerDependenciesMeta": {
    "bullmq": {
      "optional": true
    },
    "@nestjs/bullmq": {
      "optional": true
    },
    "rotating-file-stream": {
      "optional": true
    }
  },
  "main": "./index.js",
  "typings": "./index.d.ts"
}

pnpm i @lucas-labs/nest-utils (it's an internal library, published to a private npm) throws the warning:

WARN  Issues with peer dependencies found
.
└─┬ @lucas-labs/nest-utils
  ├── ✕ missing peer @nestjs/bullmq@^0.1.0
  ├── ✕ missing peer bullmq@^1.82.2
  └── ✕ missing peer rotating-file-stream@^2.1.6

Expected behavior:

No warning

Actual behavior:

Throws a missing peer warning: image

Additional information:

  • node -v prints: v16.4.0
  • Windows, macOS, or Linux?: Windows 11

lucas-labs avatar Aug 03 '22 19:08 lucas-labs

You are right. I could reproduce this. I wonder what should be the solution. We can easily hide these errors. But we can also print info messages instead. Like "supports optional peer react@16"

zkochan avatar Aug 04 '22 00:08 zkochan

actually, I was only able to reproduce this, when the peer dependency is also a regular dependency in subdependencies.

zkochan avatar Aug 04 '22 00:08 zkochan

actually, I was only able to reproduce this, when the peer dependency is also a regular dependency in subdependencies.

Hi @zkochan, thanks for your reply! I just installed typeorm, which has around 20 optional peer dependencies (a lot of databases clients/drivers) and even though we only have 3 of those peer deps installed, it didn't throw the warning message after installing it. So it might be as you said, since it's definitely not throwing the warning on every optional peer dep.

lucas-labs avatar Aug 04 '22 14:08 lucas-labs

There's a lot of usecase when the peer dependency is also a regular(or peer) dependency in subdependecies, but should remain optional. Especially using subpaths exports. Yarn PnP doesn't show errors on install time, but fails on build time if required optional peer dependency isn't installed. I wonder this is possible by pnpm too

changyoungoh avatar Aug 14 '22 15:08 changyoungoh

Have to add strict-peer-dependencies=false to .npmrc to avoid throw error

morlay avatar Aug 23 '22 02:08 morlay

This is an issue for us as well. If something is marked optional, I think the messages should not be displayed.

RobbieTheWagner avatar Mar 08 '23 14:03 RobbieTheWagner

This is an issue for us as well. If A's peer dependency B is marked optional for A, a message for missing B shouldn't be displayed when installing A as a dependency.

satouriko avatar May 25 '23 03:05 satouriko

I've hit this as well, specifically due to a deep dependency

├─┬ ember-cli 5.0.0
│ └─┬ testem 3.10.1
│   └─┬ consolidate 0.16.0
│     └── ✕ missing peer react@^16.13.1

consolidate has a lot of optional dependencies - react is optional https://github.com/tj/consolidate.js/blob/master/package.json


Without this fixed, I need to keep strict-peer-dependencies=false which I was hoping to flip to true for safer dependencies.

Techn1x avatar Jul 20 '23 06:07 Techn1x

I tried to replicate this error in the latest version (8.6.12) and it seems to work fine. In the latest version of the major 7 it throws the following error if strict-peer-dependencies is true (if false or by default it just throws a warning):

nacho@Ignacios-MacBook-Pro test % pnpm i              
Packages: +3
+++
Packages are hard linked from the content-addressable store to the virtual store.
  Content-addressable store is at: /Users/nacho/Library/pnpm/store/v3
  Virtual store is at:             node_modules/.pnpm

dependencies:
+ @ialdama/peers-meta 1.0.0
+ consolidate 1.0.1

 ERR_PNPM_PEER_DEP_ISSUES  Unmet peer dependencies

.
└─┬ @ialdama/peers-meta 1.0.0
  ├── ✕ missing peer @nestjs/common@"^7.0.0 || ^8.0.0 || ^9.0.0"
  ├── ✕ missing peer @nestjs/core@"^7.0.0 || ^8.0.0 || ^9.0.0"
  ├── ✕ missing peer reflect-metadata@^0.1.13
  └── ✕ missing peer rxjs@^7.4.0
Peer dependencies that should be installed:
  @nestjs/common@"^7.0.0 || ^8.0.0 || ^9.0.0"  @nestjs/core@"^7.0.0 || ^8.0.0 || ^9.0.0"    reflect-metadata@^0.1.13                     rxjs@^7.4.0                                  

hint: If you want peer dependencies to be automatically installed, add "auto-install-peers=true" to an .npmrc file at the root of your project.
hint: If you don't want pnpm to fail on peer dependency issues, add "strict-peer-dependencies=false" to an .npmrc file at the root of your project.

nachoaldamav avatar Aug 23 '23 09:08 nachoaldamav