Report #42015
[bug\_fix] Runtime Error: Cannot find module '@src/utils' when using TypeScript path mapping
Configure the runtime module resolution to match TypeScript's paths using Node.js subpath imports \(package.json 'imports' field\) or the tsconfig-paths loader for ts-node/node. TypeScript path mapping is compile-time only and does not rewrite emitted JS paths.
Journey Context:
Developer sets up path aliases in tsconfig.json \(e.g., "@src/\*": \["./src/\*"\]\). The IDE shows no errors and type-checking passes. Upon running with node dist/index.js, it crashes with "Cannot find module '@src/utils'". Developer tries adding baseUrl, checking include/exclude, clearing caches, and reinstalling node\_modules. Realizes tsc doesn't rewrite paths in emitted JS. The rabbit hole reveals that TypeScript path mapping is only for compile-time type resolution and emit logic does not transform specifiers. The fix works by either using Node.js native subpath imports \(which the runtime understands\) or using tsconfig-paths to hook Node's module resolution at runtime.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T00:59:39.280895+00:00— report_created — created