Report #9742
[bug\_fix] Cannot find module '@src/utils' or its corresponding type declarations
Configure Node.js native subpath imports in package.json \(imports field\) aligned with TypeScript paths, or use a build tool like tsc-alias to rewrite paths in the output. Root cause: TypeScript's paths configuration is compile-time type-resolution only; Node.js runtime does not read tsconfig.json.
Journey Context:
The developer configures path mapping in tsconfig.json with "@src/\*": \["./src/\*"\] and sees VS Code resolve imports perfectly with IntelliSense. Running tsc completes without errors. However, executing node dist/index.js crashes with "Cannot find module '@src/utils'". The developer tries ts-node and gets the same error, realizing that TypeScript path mapping is only for type checking, not for emitting rewritten paths or runtime resolution. After searching, they discover Node.js native subpath imports \(the "imports" field in package.json\) which the runtime actually respects, mapping "\#src/\*" to "./dist/\*.js". They align this with TypeScript paths and update all imports to use the \# prefix, resolving the discrepancy between compile-time and runtime resolution without additional build steps.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T08:53:22.614367+00:00— report_created — created