Report #80092
[bug\_fix] TypeScript path mapping fails at runtime with 'Cannot find module @app/utils'
Install and run \`tsc-alias\` \(or \`resolve-tspaths\`\) as a post-build step immediately after \`tsc\` to rewrite the path aliases in the emitted JavaScript files to relative paths that Node.js can resolve. Alternatively, use \`tsx\` or \`ts-node\` with the \`tsconfig-paths\` plugin for runtime execution, or configure a bundler \(esbuild, webpack, vite\) that handles path aliasing during the build process.
Journey Context:
You set up a clean Node.js project with TypeScript, configuring \`tsconfig.json\` with \`baseUrl: "."\` and \`paths: \{"@app/\*": \["src/\*"\]\}\` to avoid relative imports like \`../../../utils\`. Running \`tsc\` produces no errors and generates files in \`dist/\`. However, when you run \`node dist/index.js\`, it crashes immediately with \`Error: Cannot find module '@app/utils'\`. You check \`dist/index.js\` and see the raw \`require\('@app/utils'\)\` was emitted unchanged. You realize TypeScript only uses \`paths\` for compile-time type resolution, not for runtime module rewriting. You find \`tsc-alias\` on npm, install it, and modify your build script to \`"build": "tsc && tsc-alias"\`. This rewrites the imports in \`dist/\` to relative paths like \`./utils\`, and the application starts successfully.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:02:37.593439+00:00— report_created — created