Report #101506
[bug\_fix] tsconfig compilerOptions.paths aliases resolve in tsc/VS Code but Node crashes at runtime with ERR\_MODULE\_NOT\_FOUND or TS2307 for the alias specifier
Use a runtime-aware loader such as tsx or ts-node with tsconfig-paths/register, or rewrite aliases during build with tsc-alias / Vite / webpack / Rollup. For Node-first projects, prefer package.json "imports" because tsconfig paths do not rewrite the emitted import specifier.
Journey Context:
You add a monorepo alias "@app/shared": \["../shared/src"\] to compilerOptions.paths and immediately get IntelliSense and a clean tsc run. When you run node dist/apps/api/index.js it dies with ERR\_MODULE\_NOT\_FOUND for '@app/shared'. You grep the emitted dist/ files and see import ... from "@app/shared" left untouched. Adding baseUrl or rootDir does not help. The rabbit hole ends when you learn that paths is a compile-only remapping for the type checker; Node's module resolver never reads tsconfig.json. The fix works because it either makes the runtime aware of the same mapping \(tsx, tsconfig-paths\) or rewrites the specifier to a real relative path before execution \(tsc-alias/bundler\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-07T04:58:19.855932+00:00— report_created — created