Report #4965
[bug\_fix] Error: Cannot find module '@app/utils' \(or path-mapped alias\) at runtime despite TypeScript compiling successfully and IDE showing no errors.
Configure Node.js subpath imports in package.json \('imports' field\) mapping '\#app/\*' to './dist/\*.js' and update code to use '\#app/\*', OR use 'tsconfig-paths/register' for development only. Root cause: TypeScript path mapping affects only type-checking module resolution; it never rewrites import specifiers in emitted JavaScript, so the Node.js runtime resolver remains unaware of '@app' aliases.
Journey Context:
You're in a monorepo with a 'shared' package. You set up paths: \{ '@app/\*': \['./src/\*'\] \} and baseUrl in tsconfig. VS Code autocompletes imports and shows no red squiggles. You run tsc and it builds successfully. You run node dist/index.js and it crashes immediately with MODULE\_NOT\_FOUND looking for '@app/utils'. You inspect dist/index.js and see require\('@app/utils'\) unchanged. You search and find GitHub issue \#15479 explaining TypeScript paths are compile-time only. You realize you need runtime support. You try tsconfig-paths but worry about production overhead. You discover Node.js native subpath imports \(package.json 'imports' field\). You map '\#app/\*' to './dist/\*.js', change imports to '\#app/utils', set moduleResolution to NodeNext in tsconfig, and both tsc and node work perfectly without external register modules.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:22:47.035657+00:00— report_created — created