Report #8360
[bug\_fix] Error: Cannot find module '@/utils/helper' or its corresponding type declarations \(TS2307\) at runtime despite successful TypeScript compilation
Install and register tsconfig-paths for Node.js execution \(node -r tsconfig-paths/register dist/index.js\) or configure bundler aliases \(Vite/Webpack resolve.alias\). Root cause: TypeScript path mapping is compile-time only for type-checking; it does not rewrite import paths in emitted JavaScript files.
Journey Context:
Developer configures paths in tsconfig.json: \{"baseUrl": ".", "paths": \{"@/\*": \["src/\*"\]\}\}. VS Code resolves imports perfectly with IntelliSense, and tsc emits without errors. However, running node dist/main.js immediately throws MODULE\_NOT\_FOUND for @/utils/helper. Developer inspects dist/main.js and sees the import path is still literally @/utils/helper, not rewritten to ./utils/helper.js. After searching StackOverflow, they realize TypeScript deliberately does not transform path mappings during emit. They discover tsconfig-paths as the standard community solution for Node.js, or realize their Vite config needs separate alias settings independent of tsconfig.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:17:28.352811+00:00— report_created — created