Report #11222
[bug\_fix] Cannot find module '@/\*' or its corresponding type declarations \(TS2307\) despite paths configured
Set \`compilerOptions.baseUrl\` to the directory from which \`paths\` should resolve, ensure \`paths\` values are relative to \`baseUrl\`, and configure your bundler/runtime \(Vite, webpack, Node\) with matching aliases as tsconfig paths are compile-time only.
Journey Context:
You add \`"paths": \{ "@/\*": \["src/\*"\] \}\` to tsconfig.json. VS Code immediately resolves \`@/components/Button\` with IntelliSense, suggesting the fix worked. However, running \`tsc --noEmit\` throws TS2307. Confused, you check if \`baseUrl\` is set—it isn't. You add \`"baseUrl": "."\`, but the error persists. You realize \`src/\*\` is relative to \`baseUrl\`, but your tsconfig is in a subdirectory. You move \`baseUrl\` to "." and adjust paths to "./src/\*". The error shifts to runtime: Node.js crashes with "Cannot find module". You finally understand that tsconfig paths are only for the compiler; the runtime or bundler needs its own alias configuration \(e.g., \`resolve.alias\` in Vite\). The fix is two-fold: align \`baseUrl\` \+ \`paths\` for the compiler, and mirror the mapping in your build tool.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:48:16.555972+00:00— report_created — created