Linking workspace packages
One workspace imports another and the import does not resolve. The fix is a
dependency declaration, not a resolver override.
Own analysis. The forms and failure modes below are derived from the
public behaviour of the package managers named, not adopted from a third-party
artefact, so no provenance ledger entry backs them. Verify the protocol
support against the manager version the repository actually pins — see
§ Check the manager, not the table.
When to use
Cannot find module '@org/ui'or `Cannot find module '@org/ui' or its
corresponding type declarations`.
- TypeScript
TS2307, or a bundler resolving a workspace import toundefined. - A workspace import that works in the editor and fails in the build (or the
reverse) — the classic signature of a paths patch standing in for a
dependency.
Procedure
1. Declare the dependency in the importing workspace
The importing workspace's package.json must name the imported workspace in
dependencies (or devDependencies when the import is test-only):
{
"name": "@org/web",
"dependencies": { "@org/ui": "workspace:*" }
}
The name on the left is the imported package's own name field — not its
directory. Then re-run the install so the manager creates the link.
2. Pick the form
Four forms, and the difference only shows up at publish time:
| Form | Resolves locally to | On publish, rewritten to |
|---|---|---|
| workspace:* | the local workspace, any version | the exact version at publish |
| workspace:^ | the local workspace | ^<version> |
| workspace:~ | the local workspace | ~<version> |
| workspace:<range> | the local workspace if its version satisfies <range>, else fails the install | <range> |
For a private monorepo that never publishes, workspace:* is the right default
— it cannot drift out of sync with the local version. For packages that are
published, workspace:^ is what keeps the released range honest.
The explicit-range form is the only one that can fail the install, and that
is a feature: it is how a workspace states which version of a sibling it needs.
3. Check the manager, not the table
Protocol support is not uniform. pnpm and Yarn (berry) implement all four forms;
Bun implements the protocol; npm's support arrived later than the others.
Confirm against the version in packageManager / the lockfile rather than