피어 종속성 설정

autoInstallPeers#

  • 기본값: true
  • 유형: Boolean

true이면 누락된 필수 피어 종속성이 모두 자동으로 설치됩니다.

피어 범위를 충족하는 가장 높은 버전이 선택됩니다. 자동으로 설치된 피어는 프로젝트가 선언한 종속성이 아니므로, resolutionMode는 이를 직접 종속성이 아닌 하위 종속성으로 취급하며, 따라서 lowest-direct가 이 버전을 낮추지 않습니다.

Optional peer dependencies#

pnpm installs a missing optional peer dependency only if a version of it that satisfies the optional peer range is already installed. In that case, pnpm resolves the optional peer to that version.

When dedupePeerDependents is true, that version can come from any project in the workspace, including another project's devDependencies. For example, if one project depends on webpack and another has webpack-cli in its devDependencies, both projects get the webpack instance that has webpack-cli as its optional peer.

When dedupePeerDependents is false, or projectScopedOptionalPeers is true, that version must come from the project's own dependencies. The workspace root's dependencies also count if resolvePeersFromWorkspaceRoot is true.

pnpm skips that version if installing it would leave the project with an unmet peer dependency. This covers the version's own peers, the required peers that pnpm would install with it, and their peers in turn. dedupePeerDependents does not give the skipped peer back to the project by sharing another project's instance of the package that declares it.

pnpm also resolves optional peers this way when autoInstallPeers is false and dedupePeerDependents is true. To stop it, set both settings to false.

When selecting a workspace provider for a new project, pnpm prefers compatible optional peer versions already pinned in the lockfile.

A locked version can guide optional peer selection while another dependency still provides it. When you remove the last provider, pnpm install drops the binding even if the dependency that declares the optional peer stays on the same version. To clean up a binding left by an earlier install, run pnpm dedupe or pnpm install --fix-lockfile.

Version conflicts#

서로 다른 패키지에서 피어 종속성에 대한 버전 요구 사항이 충돌하는 경우, pnpm은 충돌하는 피어 종속성의 어떤 버전도 자동으로 설치하지 않습니다. 대신 경고가 출력됩니다. 예를 들어 한 종속성은 react@^16.0.0을 요구하고 다른 종속성은 react@^17.0.0을 요구하면 요구 사항이 충돌하므로 자동 설치가 이루어지지 않습니다.

Conflict resolution#

버전 충돌이 발생하면 어떤 버전의 피어 종속성을 설치할지 직접 판단하거나, 피어 종속성 요구 사항이 일치하도록 종속성을 업데이트해야 합니다. You can also set autoInstallPeersFromHighestMatch to true.

autoInstallPeersFromHighestMatch#

  • 기본값: false
  • 유형: Boolean

When set to true, pnpm joins conflicting peer dependency ranges with || and installs the highest version that satisfies any of them. For example, if one dependency requires react@^16.0.0 and another requires react@^17.0.0, pnpm installs the highest react@17.

Only semver ranges can be joined. Conflicting paths, aliases, or tags leave the peer dependency missing. Identical non-semver specifiers are preserved.

dedupePeerDependents#

  • 기본값: true
  • 유형: Boolean

이 설정을 true로 지정하면 피어 해석 후 피어 종속성이 있는 패키지의 중복이 제거됩니다.

This setting also lets pnpm resolve missing required and optional peers using compatible versions available elsewhere in the workspace, including transitive dependencies of other projects. Required peers can be resolved this way even when autoInstallPeers is false. A required peer satisfied this way is not reported as missing. With autoInstallPeers: false, pnpm peers check reports a separate advisory when the project and its dependency ancestors do not declare a provider.

To prevent this workspace-wide peer reuse, set both autoInstallPeers and dedupePeerDependents to false. Dependencies of the workspace root can still provide peers when resolvePeersFromWorkspaceRoot is enabled.

Resolving a package's peer does not add that peer to your project's declared dependencies. If your project's scripts run a peer package's executable, declare that package directly in your project's dependencies or devDependencies.

예를 들어 두 개의 프로젝트가 있는 워크스페이스에서 두 프로젝트 모두 종속성에 webpack이 있다고 가정해 보겠습니다. webpack은 선택적 피어 종속성에 esbuild가 있고, 프로젝트 중 하나는 종속성에 esbuild가 있습니다. 이 경우 pnpm은 node_modules/.pnpm 디렉터리에 webpack의 인스턴스 두 개를 링크합니다. 하나는 esbuild가 있고 다른 하나는 없습니다:

node_modules
  .pnpm
    webpack@1.0.0_esbuild@1.0.0
    webpack@1.0.0
project1
  node_modules
    webpack -> ../../node_modules/.pnpm/webpack@1.0.0/node_modules/webpack
project2
  node_modules
    webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
    esbuild

webpack은 두 프로젝트에서 사용되고 그중 한 프로젝트에는 esbuild가 없으므로, 두 프로젝트가 동일한 webpack 인스턴스를 공유할 수 없기 때문에 이는 타당합니다. 하지만 이는 대부분의 개발자가 기대하는 바가 아닙니다. 특히 호이스팅된 node_modules에서는 webpack의 인스턴스가 하나만 존재하기 때문입니다. Therefore, with the default dedupePeerDependents: true, pnpm deduplicates webpack when it has no conflicting peer dependencies (explanation at the end). Both projects use the same webpack instance, which is the one that has esbuild resolved:

node_modules
  .pnpm
    webpack@1.0.0_esbuild@1.0.0
project1
  node_modules
    webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
project2
  node_modules
    webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
    esbuild

충돌하는 피어 종속성이란 무엇인가요? 충돌하는 피어 종속성은 다음과 같은 시나리오를 의미합니다:

node_modules
  .pnpm
    webpack@1.0.0_react@16.0.0_esbuild@1.0.0
    webpack@1.0.0_react@17.0.0
project1
  node_modules
    webpack -> ../../node_modules/.pnpm/webpack@1.0.0_react@17.0.0/node_modules/webpack
    react (v17)
project2
  node_modules
    webpack -> ../../node_modules/.pnpm/webpack@1.0.0_react@16.0.0_esbuild@1.0.0/node_modules/webpack
    esbuild
    react (v16)

이 경우 webpack의 피어 종속성에 react가 있고 두 프로젝트의 컨텍스트에서 react가 서로 다른 두 버전으로 해석되므로 webpack의 중복을 제거할 수 없습니다.

projectScopedOptionalPeers#

Added in: v12.19.0

  • 기본값: false
  • 유형: Boolean

When true, a project gets a missing optional peer dependency only if the project's own dependencies already install a version of it. The workspace root's dependencies also count if resolvePeersFromWorkspaceRoot is true. A version that only another workspace project installs does not count.

dedupePeerDependents keeps working for everything else. It still deduplicates packages across projects, unless deduplicating would give a project an optional peer its own dependencies don't install. Required peers are not affected.

In the dedupePeerDependents example, project1 keeps the webpack instance without esbuild.

This setting has no effect when dedupePeerDependents is false, because optional peers are already resolved only from the project's own dependencies then.

Changing this setting changes the lockfile. pnpm records it in the lockfile's settings while it takes effect, so the next install resolves the lockfile again.

dedupePeers#

Deprecated. Remove this setting. For lockfile references without peer suffixes, use lockfile.format: v13.

  • 기본값: false
  • 유형: Boolean

활성화하면 피어 종속성 접미사에 전체 종속성 경로 대신 버전만 있는 식별자(name@version)를 사용하여, (foo@1.0.0(bar@2.0.0)) 같은 중첩 접미사를 제거합니다. This reduces the number of package instances in projects with many recursive peer dependencies.

이는 서로 다른 워크스페이스 프로젝트 간에 동일한 피어 종속성을 가진 패키지의 중복을 제거하는 dedupePeerDependents와는 다릅니다. dedupePeers는 피어 종속성 접미사 형식 자체를 단순화합니다.

addMissingPeerTypes#

Added in: v12.12.0

  • 기본값: false
  • 유형: Boolean

When true, every peer dependency of a dependency also makes the matching @types package an optional peer of it. A package with a peer dependency on react gets an optional peer dependency on @types/react, and one on @babel/core gets @types/babel__core. A package that already declares the @types package keeps its own declaration. pnpm does not install an @types package that nothing in your workspace depends on.

Many packages peer-depend on a library without declaring its @types package. TypeScript then looks for the types next to the package's own location. With enableGlobalVirtualStore that location is outside your project, so the types your project installs are not found. With this setting, pnpm links the @types package next to every package that peer-depends on the library, as it does with any optional peer dependency.

Changing this setting changes the lockfile.

strictPeerDependencies#

  • 기본값: false
  • 유형: Boolean

이 설정을 활성화하면 트리에 누락되었거나 유효하지 않은 피어 종속성이 있을 때 명령이 실패합니다.

resolvePeersFromWorkspaceRoot#

  • 기본값: true
  • 유형: Boolean

활성화하면 루트 워크스페이스 프로젝트의 종속성이 워크스페이스 내 모든 프로젝트의 피어 종속성을 해석하는 데 사용됩니다. 피어 종속성을 워크스페이스 루트에만 설치할 수 있고, 워크스페이스의 모든 프로젝트가 동일한 버전의 피어 종속성을 사용한다고 확신할 수 있으므로 유용한 기능입니다.

peerDependencyRules#

참고

Deprecated: peerDependencyRules only suppresses peer dependency warnings after resolution without changing peerDependencies. When you want to change or remove the declared peer dependency ranges so peer resolution itself is updated, use overrides with :peer:

  • peerDependencyRules.ignoreMissing: ["react", "@babel/*"] only silences missing-peer warnings. The overrides entries "react:peer": "-" and "@babel/*:peer": "-" remove the peer declarations and their peerDependenciesMeta entries, so packages no longer receive those peers from their parents.
  • peerDependencyRules.allowedVersions: { "button@2>react": "17" } only changes peer-mismatch reporting and has no behavior-preserving overrides replacement. Use "button@2>react:peer": "16 || 17" in overrides when you intend to widen the declared peer range and change peer resolution.
  • peerDependencyRules.allowAny: ["@babel/*"] only suppresses peer-version mismatch warnings and does not rewrite peerDependencies, so it has no direct overrides equivalent. Use "@babel/*:peer": "*" in overrides only when you intend to widen the declared peer range and change peer resolution.

peerDependencyRules continues to work for backward compatibility.

peerDependencyRules.ignoreMissing#

pnpm은 이 목록에 있는 누락된 피어 종속성에 대한 경고를 출력하지 않습니다.

예를 들어 다음 구성을 사용하면 종속성에 react가 필요하지만 react가 설치되어 있지 않을 때 pnpm이 경고를 출력하지 않습니다:

pnpm-workspace.yaml
peerDependencyRules:
  ignoreMissing:
  - react

패키지 이름 패턴도 사용할 수 있습니다:

pnpm-workspace.yaml
peerDependencyRules:
  ignoreMissing:
  - "@babel/*"
  - "@eslint/*"

ignoreMissing matches the peer package name or a glob. It does not support the parent>peer or parent@range>peer selectors accepted by allowedVersions.

peerDependencyRules.allowedVersions#

지정된 범위의 피어 종속성에 대해서는 충족되지 않은 피어 종속성 경고가 출력되지 않습니다.

예를 들어 react@16이 필요한 종속성이 있지만 react@17에서도 잘 동작한다는 것을 알고 있다면 다음 구성을 사용할 수 있습니다:

pnpm-workspace.yaml
peerDependencyRules:
  allowedVersions:
    react: "17"

이렇게 하면 피어 종속성에 react가 있는 모든 종속성에서 react v17 설치를 허용해야 한다고 pnpm에 알립니다.

특정 패키지의 피어 종속성에 대해서만 경고를 표시하지 않도록 설정할 수도 있습니다. 예를 들어 다음 구성을 사용하면 react v17은 button v2 패키지의 피어 종속성에 있거나 card 패키지의 종속성에 있는 경우에만 허용됩니다:

pnpm-workspace.yaml
peerDependencyRules:
  allowedVersions:
    "button@2>react": "17"
    "card>react": "17"

peerDependencyRules.allowAny#

allowAny는 패키지 이름 패턴의 배열로, 패턴과 일치하는 피어 종속성은 peerDependencies에 지정된 범위와 관계없이 모든 버전에서 해석됩니다. 예를 들어:

pnpm-workspace.yaml
peerDependencyRules:
  allowAny:
  - "@babel/*"
  - "eslint"

위 설정은 @babel/ 패키지 또는 eslint와 관련된 피어 종속성 버전 불일치 경고를 모두 숨깁니다.

allowAny matches the peer package name or a glob. It does not support the parent>peer or parent@range>peer selectors accepted by allowedVersions.