Report #85703
[bug\_fix] Cannot find module '@/utils' imported from /app/dist/index.js \(Runtime module resolution failure despite successful TypeScript compilation\)
Install and register 'tsconfig-paths' \(npm i -D tsconfig-paths, node -r tsconfig-paths/register dist/index.js\) or migrate to Node.js subpath imports \(package.json 'imports' field\). TypeScript path mapping is compile-time only; it does not rewrite emitted JS module specifiers.
Journey Context:
You set up 'baseUrl' and 'paths' in tsconfig.json \(e.g., '@/\*': \['src/\*'\]\) and your IDE \(VS Code\) shows no import errors. 'tsc --noEmit' passes cleanly. However, running 'node dist/index.js' crashes with 'Cannot find module'. You realize TypeScript compiled the alias literally into the emitted JS, but Node.js knows nothing about tsconfig. You try adding '.js' extensions, switching to ESM, but the alias remains unresolved. Eventually, you discover that tsconfig-paths patches the Node require\(\) at runtime to resolve the mappings, or you refactor to use Node.js native imports field which works without external tools.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T02:26:19.249045+00:00— report_created — created