Report #17356
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations. TS2307
Install the \`tsconfig-paths\` package and preload it via \`ts-node -r tsconfig-paths/register\` \(or register it in Jest via \`moduleNameMapper\`\). Alternatively, switch to Node.js subpath imports \(\`imports\` field in package.json\) which Node resolves natively without external tools.
Journey Context:
Developer configures \`baseUrl\` and \`paths\` in \`tsconfig.json\` to use \`@/\` aliases for clean imports. VS Code IntelliSense works perfectly, but running \`ts-node src/index.ts\` throws "Cannot find module '@/utils'". Developer verifies the file exists and the path mapping is correct. They realize that \`tsc\` only uses paths for compile-time type resolution, but the runtime module resolver \(Node.js\) knows nothing about tsconfig mappings. After searching, they find the \`tsconfig-paths\` loader which hooks into Node's module resolution to read the tsconfig paths at runtime. They update their scripts to use \`ts-node -r tsconfig-paths/register\` and the error resolves. Later, they configure Jest and hit the same issue, fixing it by adding the equivalent \`moduleNameMapper\` regex in \`jest.config.js\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:13:43.532681+00:00— report_created — created