Report #16689
[bug\_fix] Cannot find module '@/utils' or its corresponding type declarations at runtime despite VS Code resolving the alias correctly
TypeScript path mapping is compile-time only; Node.js runtime doesn't know about tsconfig paths. Switch to Node.js native subpath imports by adding an 'imports' field to package.json \(e.g., '\#utils': './src/utils.js'\) and reference them as '\#utils', or use a runtime loader like tsx that resolves tsconfig paths, or add tsc-alias to your build pipeline to rewrite paths in emitted JS. The root cause is that tsc emits the import specifier exactly as written in source.
Journey Context:
You set up path mapping in tsconfig.json to avoid relative path hell \('../../../utils'\), and VS Code happily autocompletes the '@/utils' import. Everything looks fine in the editor with no red squiggles. You run the app with node dist/index.js and it crashes immediately with 'Error: Cannot find module '@/utils''. You check the compiled JS and see the import statement still says '@/utils'. You realize TypeScript never rewrites paths; it only checks types. You look into tsconfig-paths/register but hit issues with ESM vs CommonJS. You consider moving to tsc-alias in your build pipeline, but then discover Node.js subpath imports which work natively without build tools.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T03:18:56.985160+00:00— report_created — created