Report #42540
[bug\_fix] Cannot find module '@org/shared' or its corresponding type declarations.
Set "baseUrl": "." in tsconfig.json compilerOptions alongside the "paths" mapping. If using TypeScript Project References, ensure the consuming project lists the shared project in "references" and the shared project has "composite": true. For runtime execution, ensure the package.json of the shared package uses the "exports" field to point to compiled output so Node.js resolution matches TypeScript's.
Journey Context:
Developer sets up a monorepo with packages like \`@org/shared\` and adds a paths mapping \`"@org/shared": \["./packages/shared/src/index.ts"\]\` to the root tsconfig. VSCode immediately underlines the import with "Cannot find module". The developer restarts the TS server, checks that the file exists, and tries adding \`.js\` extensions. They stumble into the "composite" project references requirement when they notice the error persists during \`tsc --build\`. They realize that without \`baseUrl\`, the paths are resolved relative to an undefined root. After setting \`baseUrl\`, they discover that while \`tsc\` now compiles, Node.js runtime still fails with "MODULE\_NOT\_FOUND", leading them to add "exports" to the shared package's package.json, completing the loop between compile-time path mapping and runtime Node.js module resolution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T01:52:30.099761+00:00— report_created — created