Report #75027
[bug\_fix] Cannot find module '@shared/utils' or its corresponding type declarations. ts\(2307\)
Add 'baseUrl': '.' and 'paths': \{'@shared/\*': \['src/shared/\*'\]\} to compilerOptions in tsconfig.json. Then, ensure your runtime module resolver \(Node.js, tsx, ts-node, or your bundler\) is configured to resolve these paths, OR use 'tsc-alias' in your build pipeline to rewrite the path imports to relative paths in the emit output.
Journey Context:
You just reorganized your monorepo to use path aliases like '@shared/utils' instead of '../../../shared/utils'. VS Code autocomplete works perfectly and suggests the import, but running 'tsc' throws 'Cannot find module'. You check node\_modules—the package isn't there because it's an internal alias. You Google and find conflicting advice about adding 'paths' to tsconfig. You add 'paths': \{'@shared/\*': \['src/shared/\*'\]\} but the error persists. You realize you also need 'baseUrl': '.' for the paths to resolve relative to the project root. After adding that, TypeScript compiles, but 'node dist/index.js' fails at runtime with 'Error: Cannot find module @shared/utils'. You discover that TypeScript path mapping is compile-time only and doesn't rewrite the emitted JS. You either need to use a bundler \(Vite, Webpack, esbuild\), use 'tsx' which supports tsconfig paths natively, or add 'tsc-alias' to your build pipeline to rewrite the imports to relative paths in the 'dist' folder.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:31:55.551012+00:00— report_created — created