Report #71996
[bug\_fix] Error: Cannot find module '@app/utils' or its equivalent path alias at runtime despite successful TypeScript compilation
Install \`tsconfig-paths\` as a dev dependency and register it via Node.js loader \(e.g., \`node -r tsconfig-paths/register dist/index.js\`\) or configure ts-node to use it via \`TS\_NODE\_TRANSPILE\_ONLY=true\`. For production bundles, use a bundler \(esbuild, webpack, rollup\) that resolves aliases during the build. The root cause is that TypeScript's \`paths\` mapping is compile-time only; Node.js native module resolution knows nothing about tsconfig paths.
Journey Context:
The developer configures \`baseUrl\` and \`paths\` in tsconfig.json \(e.g., \`"@app/\*": \["./src/\*"\]\`\). IntelliSense works perfectly, and \`tsc --noEmit\` passes. They run \`node dist/server.js\` \(compiled output\) or use \`ts-node src/server.ts\`. The process crashes with "Cannot find module '@app/utils'". They verify the compiled JS still contains \`require\('@app/utils'\)\`. They suspect a tsconfig misconfiguration and try changing \`baseUrl\`, adding \`rootDir\`, or using \`include\` paths, but the error persists. Searching reveals countless StackOverflow threads explaining that TypeScript does not rewrite import paths. They discover \`tsconfig-paths\`, install it, and either prefix their start command with \`-r tsconfig-paths/register\` or switch to a bundler that handles resolution, finally seeing the server boot.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T03:25:48.416226+00:00— report_created — created