pnpm: `pnpm install --filter` (to install dependencies only for selected workspace projects) not working with `dedupe-peer-dependents` set to `true`

pnpm version:

  • problem present in 8.0.0 with dedupe-peer-dependents not set (thus true = default value of v8.0.0)
  • problem not present in 8.0.0 with dedupe-peer-dependents set to false

Code to reproduce the issue:

https://github.com/pkerschbaum/pnpm-issue-workspaces-no-filter-applied-for-install

Expected behavior:

pnpm install --filter "package-a" should only install dependencies of workspace project package-a.

Actual behavior:

It installs all dependencies.
I tried to also clean the pnpm store before (rm -rf $(pnpm store path)) because I thought maybe pnpm installs more dependencies when they are on the machine already in the store, but even then all dependencies get downloaded&installed.

image

Additional information:

  • node -v prints: v16.19.0
  • Windows, macOS, or Linux?: Ubuntu 22.04.1 LTS

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 49
  • Comments: 36 (9 by maintainers)

Commits related to this issue

Most upvoted comments

As a dirty workaround, you can delete folders of unwanted packages before installing in your CI/CD. It’s not too bad in a simple monorepo where you have client/server/shared code, for instance. I delete the server folder before the client install, and I delete the client folder before the server install.

@osdiab FYI --config.dedupe-peer-dependents=false would work as same effect.

I’ve also noticed that setting node-linker=hoisted also installs all dependencies even when dedupe-peer-dependents is set to false.

These issues should be solved if we do this change: https://github.com/pnpm/pnpm/issues/8165

UPD: missed that --filter allows you to select dependencies also. Using -F project... solves my problem.

pnpm -F <project> --config.dedupe-peer-dependents=false i works fine if projects only depends on packages from NPM registry. If project depends on local packages (i.e. workspace: protocol), it also works. BUT! If local packages also have dependencies (local or from NPM), they will not be installed. I.e. package @local/backend depends on @local/client, which depends on axios. axios is not installing, build failed.

@urbanisierung i’m just appending an ellipsis i.e. pnpm--filter package-a... i. This installs package-a direct and indirect dependencies and root dependencies also.

Also i feel like my issue is unrelated to this thread, because i don’t care about deduplication. I just set dedupe-peer-dependents to false in pnpm config.

yeah it’s still a problem

We probably need a notice on doc site to indicate that install --filter is not working as expected with default config, that people need to implicitly set dedupe-peer-dependents to false to have that work.

This is probably happening because this setting is true by default: https://pnpm.io/npmrc#dedupe-peer-dependents

I need to prune the dependencies from from packages that are not related to my current build to keep my docker image small.

There is a special command for preparing a package for docker: pnpm deploy.

This is not working when node-linker=hoisted is set.

I’m using version 9.4.0.

I’m running the following command.

pnpm --filter "./packages/gql" install

You can verify it in the following project.

https://gitlab.com/bitspur/multiplatform.one/multiplatform.one

Here is my .npmrc file.

dedupe-peer-dependents=false
hoist-workspace-packages=true
link-workspace-packages=true
node-linker=hoisted
prefer-symlinked-executables=false
strict-peer-dependencies=false

Try v9.4.0

I need to prune the dependencies from from packages that are not related to my current build to keep my docker image small. Right now I have to either delete the folders as @verekia suggested or remove the workspace from the pnpm-workspaces.yaml. Either way, it completely recalculates which means I do not benefit from the lockfile.

Quite the dilemma.

Thanks for that - it does work then, but yeah due to aforementioned issues from other commenters it doesn’t help in CI. Eagerly awaiting this to be resolved, as installs are using up a lot of CI time and therefore costing my company real dollars.

i’m finding on pnpm 8.7.0 pnpm i --filter=xxx --dedupe-peer-dependents=false doesn’t work with this error:

ERROR  Unknown option: 'dedupe-peer-dependents'
Did you mean 'strict-peer-dependencies'? Use "--config.unknown=value" to force an unknown option.
For help, run: pnpm help install

Was this flag removed?

Thanks @nnhjs I’ll wait for this issue to be fixed. I have options to deal we that so it’s ok from my side.

I delete pnpm-lock file before building this specific app so i can then cp all {root}/node_modules to the app bundle (issue #6259)

It seems like pnpm i --filter=xxx --dedupe-peer-dependents=false fixes the issue indeed. Would be nice to maybe mention in the docs that this (default) setting “breaks” (depending on how you look at it 😛) some expected filters.

Do we have any updates on this issue? 🤔 I still encountered it in my project, I can’t independently run pnpm install on one package in a mono repo.

I’m experiencing this bug too. I noticed when I tried to install only root workspace dependencies and it begun installing all dependencies. I also tried clearing node_modules, pnpm store, etc.

pnpm i -w # installs all dependencies in 8.0.0