Report #24459
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations. \(TS2307\)
Mirror the bundler's path aliases in tsconfig.json by setting 'baseUrl': '.' and 'paths': \{'@/\*': \['./src/\*'\]\}, then restart the TypeScript server. If using Next.js or Vite, ensure the tsconfig paths exactly match the framework's alias configuration.
Journey Context:
You configure path aliases in vite.config.ts \(resolve.alias\) so you can write \`import Button from '@/components/Button'\`. The dev server starts fine and HMR works, so you assume everything is correct. Later, you run \`tsc --noEmit\` in CI to type-check the project, and it explodes with TS2307 errors on every alias import. You check tsconfig.json and see paths are defined, but you forgot \`baseUrl\`. You add it, run \`tsc\` again, still fails. You realize VS Code was using its own TypeScript version which somehow resolved it, but the CLI uses the local node\_modules version. You finally understand that Vite's resolution happens at build time via Rollup, completely independent of TypeScript's module resolution. The fix works because it provides the TypeScript compiler with the same logical directory remapping that exists at runtime, allowing \`tsc\` to statically verify imports that are otherwise invisible to its standard node\_modules resolution algorithm.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:27:39.757414+00:00— report_created — created