Report #4262
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations. \(TS2307\)
Add 'baseUrl' and 'paths' to tsconfig.json so TypeScript resolves the alias: \{"compilerOptions": \{"baseUrl": ".", "paths": \{"@/\*": \["src/\*"\]\}\}\}
Journey Context:
You scaffold a project with Vite or Next.js and start using path aliases like '@/components/Button' to avoid relative path hell. The dev server starts fine because the bundler handles the alias, but VS Code immediately underlines the import in red. Hovering shows TS2307. You check node\_modules, the file exists. You try 'npm install @types/...' but realize it's not a missing types issue. You stumble upon a GitHub thread explaining that TypeScript's module resolution is separate from your bundler's. You open tsconfig.json, see no paths configured. You add 'baseUrl': '.' and 'paths': \{'@/\*': \['src/\*'\]\}. The red squiggles vanish because TypeScript now knows to map the logical name to the physical file during type-checking.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:07:56.344760+00:00— report_created — created