Report #16351
[bug\_fix] Runtime Error: Cannot find module '@core/utils' imported from dist/server.js despite successful TypeScript compilation
Install 'tsconfig-paths' and launch with 'node -r tsconfig-paths/register dist/index.js', or use 'tsx'/'ts-node' which handle paths natively, or configure your bundler \(Webpack/Vite\) to resolve aliases. Root cause: TypeScript's 'paths' configuration is used solely for compile-time type resolution and declaration file generation; the compiler intentionally does not rewrite import paths in emitted JavaScript, leaving Node.js unable to resolve the aliases at runtime.
Journey Context:
You set up 'paths': \{'@core/\*': \['src/core/\*'\]\} in tsconfig to clean up imports in a growing Express API. 'npm run build' \(tsc\) completes with zero errors. You execute 'node dist/server.js' and it crashes immediately with 'Error: Cannot find module '@core/database''. You inspect 'dist/server.js' and confirm the require\('@core/database'\) is unchanged. You spend an hour trying 'rootDir' and 'outDir' combinations. You find a GitHub issue on microsoft/TypeScript stating 'paths is not meant to be rewritten'. You discover 'tsconfig-paths', which registers a Node.js require hook that reads your tsconfig.json at runtime and maps the aliases to real file paths at runtime using your tsconfig.json configuration, which is the cleanest solution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:25:25.903148+00:00— report_created — created