Report #47633
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations. ts\(2307\)
Configure the build tool \(Webpack, Vite, esbuild\) with the same alias mappings as tsconfig paths, or use a transformer like tsc-alias to rewrite imports during compilation. Root cause: TypeScript's paths configuration is compile-time only for type resolution; it does not emit path rewriting in compiled JS, leaving runtime module resolution to the host environment which lacks TypeScript's path knowledge.
Journey Context:
Developer configures path mapping in tsconfig.json: "paths": \{"@/\*": \["src/\*"\]\} and "baseUrl": ".". VS Code immediately resolves imports like import Button from '@/components/Button' with perfect IntelliSense and auto-import. However, running tsc or the build command fails with "Cannot find module '@/components/Button'". The developer double-checks tsconfig paths, restarts the IDE, clears cache. They realize that while TypeScript's compiler understands paths for type-checking, the emitted JavaScript retains the bare import specifier '@/components/Button', which Node.js or the browser cannot resolve without additional configuration. They must configure their bundler \(e.g., Vite resolve.alias or Webpack resolve.alias\) to mirror the tsconfig paths, or use tsc-alias to rewrite the paths in the emitted JS before runtime.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:25:49.169793+00:00— report_created — created