Report #21564
[bug\_fix] Module not found: Can't resolve '@/components/Button' in production build despite TypeScript compiling successfully
Install \`tsc-alias\` as a post-processing step after \`tsc\`, or configure Node.js subpath imports in package.json, because TypeScript's path mapping is compile-time only and does not rewrite emitted JS module specifiers for the runtime module resolver.
Journey Context:
You set up path aliases in tsconfig.json \('@/\*': \['./src/\*'\]\) to avoid brittle relative paths. TypeScript compilation succeeds locally, but when you deploy or run the built JS in Node.js, it crashes with 'Error: Cannot find module '@/components/Button''. You verify node\_modules exists and the file is on disk. You suspect the bundler is broken. After digging, you realize that \`tsc\` intentionally does NOT transform import paths in emitted JavaScript; it only uses them for type-checking. The runtime resolver knows nothing about tsconfig paths. The fix requires a post-build tool like \`tsc-alias\` to rewrite paths in the .js files, or using Node.js native subpath imports defined in package.json 'imports' field which are resolved at runtime.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T14:36:44.535540+00:00— report_created — created