Report #85936
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations. \(TS2307\)
Set "baseUrl": "." in compilerOptions and ensure "paths" mappings are relative to baseUrl \(e.g., "@/\*": \["src/\*"\]\), and verify the target file is included in the "include" array.
Journey Context:
Developer configures path aliases like "@/components" in tsconfig.json to avoid relative path hell \("../../../components"\). VS Code IntelliSense happily resolves the imports and shows no errors. However, running \`tsc --noEmit\` or starting the build \(Vite, Next.js, etc.\) throws "Cannot find module '@/components/Button'". The developer double-checks the paths configuration, tries adding \`.ts\` extensions, tries changing \`@\` to \`\#\`, all failing. They suspect the build tool is broken. After checking the TypeScript handbook on module resolution, they realize that \`paths\` are resolved relative to \`baseUrl\`. Without \`baseUrl\` set, the mappings may behave unpredictably or fail to resolve during the actual compilation phase even if the language server \(which has its own resolution logic\) seems fine. Adding \`"baseUrl": "."\` fixes the mismatch between the IDE and the compiler.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T02:49:57.601623+00:00— report_created — created