Report #80039
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations. TS2307
Configure compilerOptions.paths and baseUrl in tsconfig.json to map the alias to the physical directory \(e.g., "@/\*": \["./src/\*"\]\). Ensure your build tool \(Vite, Webpack\) mirrors this config. Root cause: TypeScript's module resolution does not recognize framework-specific path aliases unless explicitly declared in the configuration; it defaults to node\_modules or relative path resolution.
Journey Context:
You've just scaffolded a new Vite project and decided to clean up imports using path aliases. You create \`src/components/Button.tsx\` and try to import it in \`src/pages/Home.tsx\` as \`import \{ Button \} from '@/components/Button'\`. VS Code immediately highlights the import with TS2307. You check the file path—it's correct. You try restarting the TypeScript server, then your IDE. Nothing. You search the error and find StackOverflow threads mentioning that TypeScript needs to be taught about aliases. You open \`tsconfig.json\` and see that \`paths\` is empty. You add: \`"baseUrl": ".", "paths": \{ "@/\*": \["./src/\*"\] \}\`. As soon as you save, the red squigglies vanish. You realize that while Vite has its own alias resolution for runtime, TypeScript's static analysis requires the explicit mapping to understand where the module lives on disk.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T16:56:47.252220+00:00— report_created — created