Report #8101
[bug\_fix] TS2307: Cannot find module '@/components/Button' or its corresponding type declarations
Add 'baseUrl': '.' to the compilerOptions in tsconfig.json. Path mapping requires a baseUrl to anchor relative paths; without it, TypeScript resolves '@/\*' relative to each importing file rather than the project root, causing resolution failures even when the file exists.
Journey Context:
You just refactored a React project to use path aliases, replacing '../../../components/Button' with '@/components/Button'. You updated tsconfig.json with 'paths': \{ '@/\*': \['./src/\*'\] \}, but VS Code immediately underlines the import with 'Cannot find module'. You verify the file exists at src/components/Button.tsx. You try restarting the TS server, then TypeScript itself. You check if esModuleInterop is enabled. You stumble upon a GitHub issue explaining that 'paths' is resolved relative to 'baseUrl', and without an explicit baseUrl, TypeScript uses the importing file's directory as the reference. You add 'baseUrl': '.' and instantly all aliases resolve because TypeScript now correctly maps '@/\*' to './src/\*' relative to the tsconfig.json location.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:40:21.309013+00:00— report_created — created