Report #62745
[bug\_fix] Cannot find module '@/components/Button' or its corresponding type declarations at runtime \(Module not found\)
Install \`tsconfig-paths\` as a dev dependency and preload it via \`node -r tsconfig-paths/register dist/index.js\`, or migrate to Node.js native subpath imports \(\`"imports"\` field in package.json\) which the runtime resolves natively without build-tool helpers.
Journey Context:
Developer configures \`baseUrl\` and \`paths\` in \`tsconfig.json\` \(e.g., \`"@/\*": \["./src/\*"\]\`\) to avoid relative path hell. IntelliSense and \`tsc --noEmit\` pass cleanly. After compiling with \`tsc\` and running \`node dist/main.js\`, the process crashes with "Cannot find module '@/components/Button'". Developer tries adding \`.js\` extensions to imports, switching to ESM, or using \`ts-node\` with \`--transpile-only\`, but the error persists because TypeScript path mapping is a compile-time transformation only; the emitted JS retains the bare specifier \`@/components/Button\` which Node.js cannot resolve. The "aha" moment comes when discovering that the runtime needs a separate resolver like \`tsconfig-paths\` or must switch to Node.js native subpath imports defined in \`package.json\` under \`"imports"\` \(e.g., \`"\#components/\*": "./src/components/\*"\`\), which works in both TypeScript \(with \`tsconfig\` paths pointing to the same mapping\) and Node.js without extra runtime flags.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T11:48:09.058082+00:00— report_created — created