Report #44161
[bug\_fix] Error: Cannot find module '@/components/Button' or its corresponding type declarations. \(TS2307\)
Install and register \`tsconfig-paths\`. Run with \`node -r tsconfig-paths/register dist/index.js\` \(or use \`ts-node\` with \`require: \['tsconfig-paths/register'\]\` in tsconfig\). Ensure \`baseUrl\` is set in tsconfig.json alongside \`paths\`.
Journey Context:
Developer configures \`compilerOptions.paths\` in tsconfig.json to alias \`@/\*\` to \`src/\*\`. VS Code IntelliSense resolves imports happily, and \`tsc --noEmit\` passes. However, running \`node dist/index.js\` \(or \`ts-node src/index.ts\`\) crashes with 'Cannot find module'. Developer verifies the compiled JS files exist and the paths are correct. The rabbit hole reveals that TypeScript's \`paths\` is purely a compile-time remapping for the type-checker; it does not rewrite emitted JS import paths, nor does Node.js natively understand tsconfig aliases. The fix bridges this gap by using \`tsconfig-paths\` to hook Node's module resolution at runtime, reading the tsconfig to resolve the aliases dynamically.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T04:35:44.220084+00:00— report_created — created