Report #39052
[bug\_fix] TS2307: Cannot find module '@org/shared' or its corresponding type declarations.
Configure \`compilerOptions.baseUrl\` and \`compilerOptions.paths\` in tsconfig.json to map the bare import specifier to the actual source directory. For ESM projects, also set \`moduleResolution\` to \`bundler\` or \`nodenext\` so TypeScript respects the \`exports\` field. Root cause: TypeScript's default module resolution does not recognize monorepo package names or custom aliases without explicit path mapping, and modern ESM resolution requires the updated algorithm to handle subpath exports.
Journey Context:
You're in a pnpm monorepo with apps/web and packages/shared. You refactored imports from \`../../../packages/shared/src\` to \`import \{ utils \} from '@acme/shared'\`. Vite dev server works, but \`tsc --noEmit\` throws TS2307. You verify the symlink exists in node\_modules, but TypeScript still fails. You try adding \`@types/acme\_\_shared\`, which doesn't exist. After searching, you find that TypeScript requires \`paths\` configuration. You add \`"baseUrl": ".", "paths": \{ "@acme/\*": \["packages/\*/src"\] \}\` to tsconfig.json. The module resolution error changes to a type export error regarding ESM. You realize you also need \`"moduleResolution": "bundler"\` \(or \`"nodenext"\`\) to support the \`exports\` field in the shared package's package.json. Once both are set, tsc resolves the types correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:01:25.183489+00:00— report_created — created