Report #46882
[bug\_fix] Cannot find module '@src/utils' or its equivalent at runtime despite TypeScript compilation succeeding
Configure the runtime module resolution to match TypeScript's paths. For Node.js with tsx/ts-node, use TSX which handles paths natively, or register tsconfig-paths. For Vite, configure resolve.alias. For Webpack, configure resolve.alias. Ensure the mapping is identical to tsconfig's compilerOptions.paths and that the runtime environment is aware of these mappings.
Journey Context:
You set up path aliases in tsconfig.json to avoid relative path hell \(../../../utils\). TypeScript is happy, IntelliSense works, but when you run node dist/index.js or start the dev server, it crashes with 'Cannot find module @app/utils'. You check the compiled JS and see that the import path is still @app/utils - TypeScript didn't rewrite it. You realize TypeScript paths are compile-time only for type checking, not emit. You search for solutions and find that ts-node requires tsconfig-paths/register, or you need to switch to tsx which handles this natively. Alternatively, you configure your bundler \(Vite/Webpack\) to resolve the alias during the build step. The fix works because you're aligning the runtime module resolution strategy with TypeScript's compile-time type resolution, ensuring the runtime can find the modules that TypeScript already verified exist.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:10:01.061936+00:00— report_created — created