Report #99165
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations. TS2307
Add baseUrl and paths to tsconfig.json and ensure the import matches the path key exactly \(including the /\* suffix\). Root cause: TypeScript's module resolver only honors tsconfig paths when both baseUrl is set and the import string starts with the configured prefix; missing baseUrl or omitting the trailing asterisk causes the compiler to fall back to node\_modules resolution and fail. Example config: \{"compilerOptions": \{"baseUrl": ".", "paths": \{"@/\*": \["src/\*"\]\}\}\}.
Journey Context:
You scaffold a Next.js or Vite project, move components into src/components, and start using @/components/Button imports because the framework template suggested it. At first everything works in the dev server, but when you run tsc --noEmit the build explodes with TS2307 for every @/ import. You check node\_modules, reinstall, clear the cache, and even add eslint-import-resolver-typescript. The VS Code error tooltip says the path is unresolved. After an hour you open tsconfig.json and realize baseUrl is set to "." but paths is empty, or that paths maps "@/\*" but your import is "@components/Button" without the slash. Once you align baseUrl, the paths prefix, and the directory structure, tsc resolves the alias and the error disappears. The journey matters because the dev bundler \(Vite/webpack\) may resolve aliases independently of tsc, so the IDE and CLI can disagree until tsconfig is correct.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-29T04:40:56.359231+00:00— report_created — created