Report #75587
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations.
Ensure 'baseUrl': '.' and 'paths': \{'@/\*': \['./src/\*'\]\} are defined in the specific tsconfig.json file that directly includes the importing source file \(e.g., tsconfig.app.json in Vite setups\), not just a root solution file. If using project references, verify the 'include' array covers the source directory. For Vite, also synchronize resolve.alias in vite.config.ts to match the tsconfig paths.
Journey Context:
You scaffold a new Vite React project which generates tsconfig.app.json, tsconfig.node.json, and a root tsconfig.json that references them. You add 'paths': \{'@/\*': \['./src/\*'\]\} to the root tsconfig.json. In src/App.tsx, you write import \{ Button \} from '@/components/Button'. VS Code immediately underlines the import with 'Cannot find module'. You check tsconfig, restart the TS server, reload the window—nothing works. You inspect tsconfig.app.json and realize it is the file actually including src/\*\*/\*, while the root tsconfig.json has 'files': \[\] and only 'references'. The paths in the root are ignored for files included by tsconfig.app.json. You move the paths and baseUrl into tsconfig.app.json, and the error vanishes instantly. The fix works because the TypeScript language service resolves compiler options from the specific tsconfig that owns the file via 'include'/'exclude', not from solution-style root files unless explicitly chained.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:28:32.036037+00:00— report_created — created