-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Self-service
- I'd be willing to implement a fix
Describe the bug
When using yarn workspaces focus --production, peer dependencies that are satisfied by an ancestor workspace's production dependencies fail validation if the intermediate package only has the peer in devDependencies.
Specifically:
- Package A (
@repro/config) has a dependency (zod-validation-error) that requireszodas a peer - Package A declares
zodas apeerDependencyand has it indevDependenciesfor local development - Package B (
@repro/server) depends on Package A and haszodin its productiondependencies
Full install works because devDependencies are installed, satisfying the peer requirement.
Production install (yarn workspaces focus --production) fails with YN0002 because:
devDependenciesare stripped from Package A- Yarn checks that Package A provides
zodtozod-validation-error - Even though Package B has
zodin production dependencies, Yarn doesn't consider ancestors when validating peer requirements
The peer dependency IS available at runtime due to hoisting, but the validation fails before installation completes.
To reproduce
Minimal reproduction repository: https://github.com/georgewitteman/yarn-YN0002
Clone and test
git clone https://github.com/georgewitteman/yarn-YN0002
cd yarn-YN0002
corepack enable
yarn install # ✓ Succeeds
yarn workspaces focus --production @repro/server # ✗ Fails with YN0002
Error:
YN0002: @repro/config@workspace:packages/config doesn't provide zod, requested by zod-validation-error
Environment
System:
OS: Linux 6.8 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
CPU: (8) x64 AMD EPYC 7763 64-Core Processor
Binaries:
Node: 20.19.2 - /tmp/xfs-0c52103d/node
Yarn: 4.12.0 - /tmp/xfs-0c52103d/yarn
npm: 10.8.2 - /usr/local/bin/npmAdditional context
.yarnrc.yml configuration:
- nodeLinker: node-modules
- logFilters: [{code: YN0002, level: error}]
The dependency tree is:
@repro/server
├─D> zod (production dependency)
└─D> @repro/config (peerDep: zod, devDep: zod)
└─D> zod-validation-error (peerDep: zod)
According to https://yarnpkg.com/configuration/yarnrc#logFilters and https://dev.to/arcanis/implicit-transitive-peer-dependencies-ed0, Yarn enforces peer dependencies at every level. However, this creates an impossible situation for production installs where:
- A library package wants consumers to provide a peer dependency
- The library has a dependency that also needs that peer
- The library cannot satisfy its own dependency's peer requirement in production without duplicating the dependency