Report #74599
[bug\_fix] Cannot find module '@app/components' or its corresponding type declarations at runtime despite successful compilation
Install \`tsconfig-paths\` and preload it via \`node -r tsconfig-paths/register dist/index.js\`, or configure the bundler \(Vite/Webpack/esbuild\) to resolve the alias during the build, or migrate to Node.js native subpath imports \(\`package.json\` "imports" field\) which are resolved at runtime.
Journey Context:
Developer configures \`paths\` in \`tsconfig.json\` \(e.g., \`"@app/\*": \["src/\*"\]\`\) to eliminate relative path hell. TypeScript compiles without errors, IDE IntelliSense works perfectly, but running the compiled output in Node.js throws "Cannot find module '@app/components'". The developer spends hours checking \`baseUrl\`, deleting \`node\_modules\`, trying different \`moduleResolution\` settings, and searching for "TypeScript path alias not working". They eventually realize that \`tsconfig.json\` \`paths\` is purely a compile-time construct for the type checker and emit redirection; Node.js's native ESM/CJS resolver knows nothing about \`tsconfig.json\`. The fix works by bridging this gap: \`tsconfig-paths\` reads the config at runtime to patch the module loader, or the build tool is told to physically rewrite the import paths during bundling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T07:48:53.635500+00:00— report_created — created