Report #99640
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations. ts\(2307\)
Add a \`baseUrl\` and \`paths\` mapping to \`tsconfig.json\` that mirrors the alias configured in the build tool, e.g. \`\{ "compilerOptions": \{ "baseUrl": ".", "paths": \{ "@/\*": \["src/\*"\] \} \} \}\`. Restart the TS server / IDE and ensure the same alias exists in \`vite.config.ts\`/\`webpack.config.js\`/\`next.config.js\`.
Journey Context:
You scaffold a React \+ Vite project, add a path alias \`@/\` in \`vite.config.ts\` so imports look clean, and everything builds fine. Then you open \`App.tsx\`, type \`import \{ Button \} from '@/components/Button'\`, and VS Code immediately underlines it in red with TS2307. The app still runs because Vite resolves the alias at bundle time, but TypeScript's language server doesn't know about it. You first try installing \`@types/node\`, then deleting \`node\_modules\`, then adding \`"include": \["src/\*\*/\*"\]\`. None of that helps because the compiler has no \`paths\` rule. You open \`tsconfig.app.json\`, see only \`baseUrl\` is set, add \`"paths": \{ "@/\*": \["./src/\*"\] \}\`, hit Command\+Shift\+P → TypeScript: Restart TS Server, and the red squiggle vanishes. The root cause is that \`paths\` is the only mechanism TypeScript uses to rewrite non-relative module specifiers; bundler aliases are invisible to \`tsc\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-30T04:48:51.043724+00:00— report_created — created