Report #16358
[bug\_fix] TS2307: Cannot find module '@components/Button' or its corresponding type declarations
Ensure 'baseUrl' is set in tsconfig.json \(usually to '.'\), and verify the 'paths' configuration maps the alias to the correct relative path from baseUrl \(e.g., '@components/\*': \['src/components/\*'\]\). Root cause: The 'paths' compiler option is resolved relative to 'baseUrl'. If 'baseUrl' is omitted, 'paths' may be resolved relative to the location of the tsconfig.json in unexpected ways, or not at all, causing TypeScript to fail to map the alias to the source file during module resolution.
Journey Context:
You migrate a Create React App project to Vite and want to set up path aliases to avoid '../../components' hell. You create a tsconfig.json in the project root and add 'compilerOptions': \{ 'paths': \{ '@/\*': \['./src/\*'\] \} \}. You try to import 'import Header from '@/components/Header'' but VS Code shows 'TS2307: Cannot find module '@/components/Header''. You check that the file exists at './src/components/Header.tsx'. You try adding 'include': \['src/\*\*/\*'\] to tsconfig but it doesn't help. You search for the error and find a GitHub comment stating that 'paths' without 'baseUrl' is like a relative path without a starting point. You add 'baseUrl': '.' to compilerOptions. Instantly, the red squiggly lines disappear and IntelliSense resolves the import correctly to './src/components/Header.tsx'. You realize that 'baseUrl' serves as the anchor for all relative path lookups in 'paths', and without it, TypeScript couldn't resolve where './src/\*' was supposed to start from.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:26:23.909361+00:00— report_created — created