Report #57166
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations
TypeScript path mapping \(baseUrl/paths\) is compile-time only; the runtime \(Node.js\) does not resolve these aliases. Install and use 'tsconfig-paths' \(e.g., \`node -r tsconfig-paths/register dist/index.js\`\) or use a build tool \(Vite, webpack, tsc-alias\) that rewrites imports during bundling. Alternatively, use Node.js subpath imports \(package.json 'imports' field\) which both TypeScript and Node natively support.
Journey Context:
Developer sets up a clean architecture folder structure and configures \`baseUrl\` and \`paths\` in tsconfig.json to use aliases like \`@/components\`. VS Code autocomplete works perfectly, and \`tsc --noEmit\` passes. However, running \`node dist/server.js\` throws 'Error: Cannot find module @/components/Button'. Developer checks that the JS output still contains \`require\('@/components/Button'\)\`, realizing TypeScript never rewrites paths—it only checks types. They search and find GitHub issues explaining that path mapping is a TypeScript design-time feature only. They try \`tsc-alias\` in post-build, which fails silently. They eventually discover \`tsconfig-paths\` and run \`node -r tsconfig-paths/register dist/server.js\`, which works because it hooks Node's \`Module.\_resolveFilename\` to respect tsconfig paths at runtime.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T02:26:33.471566+00:00— report_created — created