Report #65613
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations.
Configure \`compilerOptions.paths\` in tsconfig.json to map the alias \(e.g., "@/\*": \["./src/\*"\]\), ensure \`baseUrl\` is set to the directory containing the src folder \(e.g., "."\), and verify the build tool \(Vite, Webpack, esbuild\) is configured with identical alias resolution. The root cause is that TypeScript's module resolution strategy \(Node or NodeNext\) treats "@/components/Button" as a bare specifier that must be explicitly mapped to a relative file system path via paths configuration.
Journey Context:
Developer scaffolds a React project with Vite and immediately configures path aliases in vite.config.ts \(resolve.alias: \{ '@': '/src' \}\). The dev server runs fine, but VSCode instantly underlines every import starting with "@/" with "Cannot find module". The developer restarts the TypeScript server \(Cmd\+Shift\+P > TypeScript: Restart TS Server\) to no avail. They search for the error and land on StackOverflow threads mentioning tsconfig paths. They open tsconfig.json and add "paths": \{ "@/\*": \["./src/\*"\] \}, but the error persists. After more searching, they realize they omitted "baseUrl": "." which is required for the paths to resolve relative to the project root. Once baseUrl is added, VSCode recognizes the modules. However, running \`tsc --noEmit\` now fails with the same error. The developer realizes that tsc checks paths independently of the IDE's language service, and their build pipeline \(esbuild via Vite\) was configured, but the \`tsc\` command used for type checking also needs the tsconfig to be complete. The fix works because TypeScript's module resolution algorithm only applies path mappings when both \`baseUrl\` and \`paths\` are specified, and the mappings must align with the runtime module resolution strategy of the bundler.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T16:36:40.971532+00:00— report_created — created