Report #20754
[bug\_fix] Error: Cannot find module '@app/utils' or its corresponding type declarations. Require stack: /app/dist/main.js
Install \`tsconfig-paths\` as a production dependency and preload it at runtime with \`node -r tsconfig-paths/register dist/main.js\`, or alternatively use \`tsc-alias\` as a post-build step to physically rewrite the path aliases to relative paths in the emitted JS files.
Journey Context:
Developer configures \`compilerOptions.paths\` in tsconfig.json \(e.g., \`"@app/\*": \["src/\*"\]\`\) to avoid relative path hell. VS Code IntelliSense works perfectly, and \`tsc\` emits no diagnostics. However, executing the compiled output with \`node dist/main.js\` immediately crashes with "Cannot find module '@app/utils'". The developer investigates and discovers that TypeScript's \`tsc\` compiler only uses path mapping for type-checking during compilation; it intentionally does not rewrite the import specifiers in the emitted JavaScript, as it is a type-checker, not a bundler. The fix works by either hooking Node's \`Module.\_resolveFilename\` at runtime via \`tsconfig-paths\` to resolve the aliases according to tsconfig, or by post-processing the JS files to replace aliases with relative paths, making the code portable to any runtime without special hooks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:14:34.114282+00:00— report_created — created