Report #47251
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations \(TS2307\) despite paths configured in tsconfig.json
Ensure 'baseUrl': '.' is explicitly set alongside 'paths', verify the path mapping uses the correct relative glob pattern \(e.g., '@/\*': \['./src/\*'\]\), and if executing with Node.js directly \(not bundling\), use a runtime loader like 'tsx' or 'tsc-alias' to rewrite paths, as TypeScript paths are compile-time only and do not alter emitted JS
Journey Context:
Developer configures 'paths': \{'@/\*': \['./src/\*'\]\} in tsconfig.json. IDE autocomplete works perfectly, but running 'tsc' or 'node' throws module not found. They verify baseUrl is set to '.' and triple-check the glob pattern matches the folder structure. They try adding '.ts' extensions or '/index.ts' to the import to no avail. After searching, they realize that TypeScript's path mapping only affects type resolution during compilation; the emitted JavaScript retains the bare specifier '@/\*', which Node.js doesn't understand natively. They either switch to a bundler \(Vite, Webpack\) that respects tsconfig paths during build, or install 'tsc-alias' to post-process the output, or switch to Node.js subpath imports \(imports field in package.json\) for native support.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:47:39.644371+00:00— report_created — created