Monorepo Workspace Package Resolution (2026)
The Error
Error: Cannot find module '@myorg/shared-utils' or its corresponding type declarations.
Require stack:
- /packages/api/src/index.ts
Module not found in workspace: @myorg/shared-utils is not linked
This error occurs in monorepo setups when one workspace package cannot resolve another. The dependency exists in the monorepo but is not linked correctly.
The Fix
- Ensure the dependency uses the workspace protocol in package.json:
{
"dependencies": {
"@myorg/shared-utils": "workspace:*"
}
}
- Run install to link workspaces:
# For pnpm:
pnpm install
# For npm:
npm install
# For yarn:
yarn install
- Verify the link exists:
ls -la node_modules/@myorg/shared-utils
# Should be a symlink to ../../packages/shared-utils
- Rebuild the shared package:
cd packages/shared-utils && npm run build
cd ../..
npx tsc --noEmit
Why This Happens
Monorepo workspace packages must be explicitly declared in the root package.json workspaces array and properly referenced with workspace protocols. When Claude creates a new package or adds a cross-package import, it may not update the workspace configuration. Without proper linking, Node’s module resolution cannot find the sibling package.
If That Doesn’t Work
- Verify the package is listed in root workspaces:
python3 -c "import json; print(json.load(open('package.json')).get('workspaces', 'NOT SET'))"
- Check for TypeScript path mapping:
{
"compilerOptions": {
"paths": {
"@myorg/*": ["packages/*/src"]
}
}
}
- Clean and reinstall:
rm -rf node_modules packages/*/node_modules
pnpm install
Prevention
Add this to your CLAUDE.md:
# Monorepo
- All cross-package deps must use workspace:* protocol.
- After creating a new package, add it to root workspaces array.
- Run pnpm install after any dependency change.
- Add TypeScript paths for @myorg/* in root tsconfig.json.
See Also
- Claude Code Monorepo: Best Setup Guide (2026)
- ESM vs CJS Module Resolution Failure — Fix (2026)
- Claude Code Monorepo Workspace Resolution Failure — Fix (2026)
Related Error Messages
This fix also applies if you see variations of this error:
- Connection or process errors with similar root causes in the same subsystem
- Timeout variants where the operation starts but does not complete
- Permission variants where access is denied to the same resource
- Configuration variants where the same setting is missing or malformed
If your specific error message differs slightly from the one shown above, the fix is likely the same. The key indicator is the operation that failed (shown in the stack trace) rather than the exact wording of the message.
Frequently Asked Questions
Does this error affect all operating systems?
This error can occur on macOS, Linux, and Windows (WSL). The exact error message may differ slightly between platforms, but the root cause and fix are the same. macOS users may see additional Gatekeeper or notarization prompts. Linux users should check that the relevant system packages are installed. Windows users should ensure they are running inside WSL2, not native Windows.
Will this error come back after updating Claude Code?
Updates can occasionally reintroduce this error if the update changes default configurations or dependency requirements. After updating Claude Code, verify your project still builds and runs correctly. If the error returns, reapply the fix and check the changelog for breaking changes.
Can this error cause data loss?
No, this error occurs before or during an operation and does not corrupt existing files. Claude Code’s edit operations are atomic — they either complete fully or not at all. However, if the error occurs during a multi-step operation, you may have partial changes that need to be reviewed with git diff before continuing.
How do I report this error to Anthropic if the fix does not work?
Open an issue at github.com/anthropics/claude-code with: (1) the full error message including stack trace, (2) your Node.js version (node --version), (3) your Claude Code version (claude --version), (4) your operating system and version, and (5) the command or operation that triggered the error.
Related Guides
Try it: Paste your error into our Error Diagnostic for an instant fix.