Параметри прямих залежностей
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 зв'яже два екземпляри webpack з текою node_modules/.pnpm: один з 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, оскільки webpack має react у своїх прямих залежностях, а react розвʼязується з двох різних версій у контексті двох проєктів.
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. Theoverridesentries"react:peer": "-"and"@babel/*:peer": "-"remove the peer declarations and theirpeerDependenciesMetaentries, 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-preservingoverridesreplacement. Use"button@2>react:peer": "16 || 17"inoverrideswhen you intend to widen the declared peer range and change peer resolution.peerDependencyRules.allowAny: ["@babel/*"]only suppresses peer-version mismatch warnings and does not rewritepeerDependencies, so it has no directoverridesequivalent. Use"@babel/*:peer": "*"inoverridesonly when you intend to widen the declared peer range and change peer resolution.
peerDependencyRules continues to work for backward compatibility.
peerDependencyRules.ignoreMissing#
pnpm не виводитиме попередження про відсутні у цьому списку прямі залежності.
Наприклад, у наступній конфігурації pnpm не виводитиме попередження, якщо залежність потребує react, але react не встановлено:
peerDependencyRules:
ignoreMissing:
- react
Також можна використовувати шаблони назв пакунків:
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, то ви можете використовувати наступну конфігурацію:
peerDependencyRules:
allowedVersions:
react: "17"
Це скаже pnpm, що будь-яка залежність, яка має react у своїх прямих залежностях, повинна дозволити встановлення react v17.
Також можна вимкнути попередження лише для прямих залежностей певних пакунків. Наприклад, у наведеній нижче конфігурації react v17 буде дозволено лише тоді, коли він є в однорангових залежностях пакунка button v2 або в залежностях будь-якого пакунка card:
peerDependencyRules:
allowedVersions:
"button@2>react": "17"
"card>react": "17"
peerDependencyRules.allowAny#
allowAny — масив шаблонів назв пакунків, будь-яка пряма залежність, що відповідає шаблону, буде розвʼязана з будь-якої версії, незалежно від діапазону, вказаного у peerDependencies. Наприклад:
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.