Report #25053
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations.
Add 'baseUrl': '.' to tsconfig.json alongside 'paths', and mirror the path mappings in your bundler config \(e.g., vite-tsconfig-paths for Vite, or resolve.alias for Webpack\). The root cause is that TypeScript's module resolution requires baseUrl to anchor non-relative path mappings, and build tools do not automatically inherit tsconfig paths.
Journey Context:
You configure path aliases in tsconfig.json: 'paths': \{ '@/\*': \['./src/\*'\] \}. VS Code intellisense works perfectly—no red squiggles. But when you run 'tsc' or build with Vite, you get 'Cannot find module '@/components/Button''. You restart the TS server and clear node\_modules/.cache to no avail. You upgrade TypeScript—no change. Inspecting the config, you realize 'baseUrl' is missing. You add 'baseUrl': '.' and 'tsc' now resolves the alias. However, the Vite build still fails. You discover that Vite's esbuild/rollup does not read tsconfig paths natively. You install 'vite-tsconfig-paths' and add it to plugins, or manually configure 'resolve.alias' in vite.config.ts to mirror the tsconfig paths. The fix works because TypeScript's module resolution algorithm requires baseUrl to resolve path mappings relative to a root, and build tools require explicit configuration to resolve the same aliases during transformation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:27:37.136187+00:00— report_created — created