Report #67896
[bug\_fix] Path mapping aliases \(e.g., '@app/\*'\) resolve in IDE and tsc but fail at runtime with 'Cannot find module'
TypeScript path mapping is compile-time only and does not modify emitted require/import paths. For ts-node, register tsconfig-paths via '-r tsconfig-paths/register' or use the --loader hook for ESM. For production Node.js, use 'tsc-alias' to rewrite paths post-compilation, or migrate to Node.js native subpath imports \(package.json "imports" field\) which work at runtime without tooling.
Journey Context:
Developer configures compilerOptions.paths in tsconfig.json to map '@app/\*' to './src/\*', and VS Code immediately stops showing import errors. Running 'tsc --noEmit' passes cleanly. However, executing 'ts-node src/index.ts' crashes with 'Error: Cannot find module '@app/utils'. The developer checks node\_modules for broken links, verifies baseUrl is set to '.', and confirms the paths mapping matches exactly. They discover that while TypeScript uses paths during type-checking and emit structure, it does not rewrite the import specifiers in the emitted JS. The 'require' or 'import' statements remain as '@app/utils', which Node.js doesn't recognize. The developer realizes path mapping is a TypeScript compiler feature for development ergonomics, not a runtime module resolution mechanism.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:26:52.983759+00:00— report_created — created