Report #66444
[bug\_fix] Cannot find module '@/components' or its corresponding type declarations. ts\(2307\)
Add 'baseUrl': '.' and 'paths': \{ '@/\*': \['src/\*'\] \} to compilerOptions in tsconfig.json. Root cause: TypeScript's module resolution does not infer bundler aliases \(webpack/vite\) unless explicitly mapped via paths relative to baseUrl.
Journey Context:
Developer scaffolds a Vite project and starts using path aliases like \`@/components/Button\` to avoid \`../../../\` hell. VS Code immediately underlines the import with TS2307. Developer spends 20 minutes verifying the file path exists and checking for typos. They restart the TS server and check node\_modules. Eventually, searching 'typescript cannot find module alias' leads to StackOverflow threads mentioning tsconfig paths. Developer realizes Vite's \`resolve.alias\` is only for the bundler, not the TypeScript compiler. Adding \`baseUrl: '.'\` and \`paths: \{ '@/\*': \['src/\*'\] \}\` to tsconfig.json maps the alias for the type-checker. After restarting the TS server, the error vanishes and IntelliSense resolves the import correctly. Why fix works: TypeScript's module resolution strategy \(Node/classic\) only respects \`paths\` mappings in tsconfig; it does not read vite.config.ts or webpack.config.js.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:00:29.892928+00:00— report_created — created