yarn "This module isn't specified in a manifest" - Fix Workspace Resolution in CI
Yarn enforces that every import is a declared dependency of the importing workspace. "This module isn’t specified in a manifest" means code requires a package not listed in that package.json - Yarn (notably under PnP) will not resolve undeclared dependencies.
What this error means
A build or test fails with Error: <importer> tried to access <pkg>, but it isn't specified in its dependencies; this makes the require call ambiguous and unsound. It surfaces undeclared (often phantom) dependencies that node_modules hoisting used to hide.
Error: foo tried to access lodash, but it isn't specified in its
dependencies; this makes the require call ambiguous and unsound.
Required package: lodash
Required by: foo@workspace:packages/fooCommon causes
An undeclared (phantom) dependency
Code imports a package that was only available via hoisting, not declared in the workspace’s package.json. Yarn PnP refuses to resolve it.
A dependency declared in the wrong workspace
In a monorepo, the package is a dependency of a different workspace than the one importing it, so the importing manifest does not list it.
How to fix it
Declare the dependency where it is used
Add the package to the importing workspace’s package.json and reinstall.
# from the importing workspace
yarn workspace @acme/foo add lodash
yarn installAudit phantom dependencies
- List the imports each workspace uses and confirm they are declared there.
- Move dependencies to the workspace that actually imports them.
- Avoid relying on hoisting that PnP intentionally does not provide.
How to prevent it
- Declare every import in the workspace that uses it.
- Audit for phantom dependencies, especially before adopting PnP.
- Keep monorepo dependencies scoped to the right workspace.