Report #94613
[bug\_fix] Cannot find module '@app/utils' or its corresponding type declarations
Configure path mapping in tsconfig.json with 'baseUrl' and 'paths', then ensure the runtime environment handles the resolution. For Node.js execution without a bundler, use the Node.js 'imports' field in package.json for native subpath imports, or register tsconfig-paths with 'node --loader tsconfig-paths/register' or 'ts-node -r tsconfig-paths/register'. If bundling with Vite/Webpack, configure the bundler's resolve.alias to match tsconfig paths. Root cause: TypeScript path mapping only affects compile-time type resolution and emit; it does not rewrite module specifiers in the emitted JS or instruct Node.js how to resolve modules at runtime.
Journey Context:
You add 'paths': \{'@app/\*': \['./src/\*'\]\} and 'baseUrl': '.' to tsconfig.json. VS Code immediately resolves the imports and provides IntelliSense, but running the code with 'ts-node src/index.ts' throws 'Error: Cannot find module @app/utils'. You verify the path mapping syntax, try adding '.js' extensions to the paths values, and check that 'include' in tsconfig covers the src directory. You suspect ts-node is ignoring paths, so you compile with 'tsc' and run the output with Node.js, but get the same error. After investigating, you realize that TypeScript's paths are only for the compiler's module resolution during type-checking; the emitted JavaScript retains the original '@app/utils' import specifier, which Node.js cannot resolve because it knows nothing about tsconfig paths. You then look into Node.js subpath imports or tsconfig-paths.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:23:24.310439+00:00— report_created — created