Report #37629
[bug\_fix] TS2307: Cannot find module '@/utils' or its corresponding type declarations. \(Runtime error after successful tsc compilation\)
Register tsconfig-paths at runtime \(node -r tsconfig-paths/register dist/index.js\), or use Node.js subpath imports \(imports field in package.json\), or bundle with esbuild/webpack that rewrites paths. Root cause: TypeScript path mapping is compile-time only; the emitted JavaScript retains the alias string, and Node.js module resolution doesn't read tsconfig.json.
Journey Context:
Developer configures paths in tsconfig.json: \{"baseUrl": ".", "paths": \{"@/\*": \["src/\*"\]\}\}. VS Code happily auto-imports using @/utils, and tsc compiles without errors. However, running node dist/main.js throws 'Error: Cannot find module '@/utils''. Developer checks that baseUrl is set, tries changing paths to absolute paths, even copies jsconfig.json. They inspect the compiled dist/main.js and see the import \* as utils from '@/utils'; is untouched. Realizing that TypeScript doesn't rewrite import paths, they search for runtime solutions and find tsconfig-paths or decide to switch to native Node.js imports field.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T17:38:31.321420+00:00— report_created — created