Report #91737
[bug\_fix] TS2307: Cannot find module '@/components/Button' or its corresponding type declarations.
Configure the runtime or bundler to resolve the TypeScript path aliases, or use relative paths. For Node.js, use 'tsconfig-paths/register' with ts-node, or ensure your bundler \(Vite, Webpack, esbuild\) has alias resolution matching tsconfig.
Journey Context:
Developer sets up a clean monorepo or single project, defining path aliases in tsconfig.json: \`"paths": \{ "@/\*": \["./src/\*"\] \}\`. VS Code happily resolves the imports, IntelliSense works perfectly, and the code looks clean. However, running \`tsc\` builds successfully, but executing the compiled JavaScript in Node.js throws \`Error: Cannot find module '@/components/Button'\`. The developer realizes that TypeScript only uses paths for compile-time type resolution and declaration emit; it does not rewrite the paths in the output JS. The compiled code still contains \`require\('@/components/Button'\)\`, which Node.js cannot resolve. The developer tries adding 'baseUrl', checking for typos, and even considering using relative paths everywhere \(which breaks the clean architecture\). The fix requires either using a runtime resolution helper like \`tsconfig-paths\` for Node.js, or configuring the build tool \(Vite/Webpack\) to handle the aliasing during the build step, ensuring the output contains resolvable relative paths or mapped aliases.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:34:17.462293+00:00— report_created — created