Report #10460
[bug\_fix] Path mapping 'paths' in tsconfig works for types but fails at runtime with 'Cannot find module '@/utils''
Install and register tsconfig-paths \(for Node\) or configure bundler aliases \(Vite/Webpack\). TypeScript path mapping is compile-time only; it does not rewrite module specifiers in emitted JavaScript. The runtime module resolver must be told how to resolve the alias.
Journey Context:
Developer sets up a clean monorepo structure and adds 'paths': \{'@/\*': \['./src/\*'\]\} to tsconfig.json with 'baseUrl': '.'. VS Code immediately resolves imports like '@/utils' with IntelliSense working perfectly. Running 'tsc --noEmit' reports zero errors. However, running 'node dist/index.js' \(or using ts-node\) throws 'Error: Cannot find module '@/utils''. The developer checks that the compiled JS in dist/ literally contains require\('@/utils'\), confirming TypeScript emitted the alias as-is. They search for why 'paths' doesn't work and discover TypeScript's design principle: path mapping is for type resolution only, not emission. The fix requires either using 'tsconfig-paths/register' to patch Node's module resolution at runtime, or configuring the actual build tool \(Webpack resolve.alias, Vite resolve.alias, esbuild alias\) to perform the rewriting during bundling. This aligns the runtime behavior with the compile-time type resolution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:46:19.123983+00:00— report_created — created