Report #11733
[bug\_fix] Cannot find module '@/utils/foo' at runtime despite TypeScript compilation succeeding \(TSConfig paths resolution failure\)
Use \`tsc-alias\` to rewrite path aliases to relative paths after \`tsc\` compilation, or use Node.js Subpath Imports \(\`imports\` field in package.json\) instead of tsconfig paths. Root cause: TypeScript's \`paths\` mapping is a compile-time transform only; it does not rewrite module specifiers in the emitted JavaScript, leaving Node.js unable to resolve the bare-specifier aliases at runtime.
Journey Context:
You scaffold a monorepo and define \`baseUrl\` and \`paths\` in \`tsconfig.json\` \(e.g., \`"@/\*": \["src/\*"\]\`\). \`tsc\` builds with no errors. You run \`node dist/main.js\` and immediately crash with \`Error \[ERR\_MODULE\_NOT\_FOUND\]: Cannot find module '@/utils/foo'\`. You verify \`dist/utils/foo.js\` exists. You check the compiled \`dist/main.js\` and see \`require\("@/utils/foo"\)\` is untouched. You spend an hour tweaking \`rootDir\`, \`outDir\`, and \`rootDirs\` assuming it's a resolution mapping issue. You eventually read the TypeScript handbook fine print stating that paths are not re-written. You either adopt \`tsc-alias\` in your build pipeline \(\`tsc && tsc-alias\`\) or migrate to Node.js native subpath imports which are respected by both TypeScript \(with \`--moduleResolution node16\`\) and Node.js at runtime.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:12:12.059108+00:00— report_created — created