Report #52838
[bug\_fix] Error: Cannot find module '@/lib/utils' or TS2307: Cannot find module '@/components/Button' imported from src/index.ts
For ts-node/ts-node-dev: Register tsconfig-paths at runtime with \`node -r tsconfig-paths/register\` or \`ts-node --transpile-only --project tsconfig.json -r tsconfig-paths/register src/index.ts\`. For production builds: Use a bundler \(esbuild, webpack, Vite\) that respects tsconfig paths during the build, or use \`tsc-alias\` to rewrite paths in the emitted JS after \`tsc\` compilation, or migrate to Node.js native subpath imports \(\`imports\` field in package.json\) which Node.js resolves at runtime without TypeScript-specific tooling.
Journey Context:
Developer sets up path aliases in \`tsconfig.json\` with \`baseUrl: "."\` and \`paths: \{ "@/\*": \["src/\*"\] \}\`. VS Code IntelliSense works perfectly—imports resolve, go-to-definition works, no red squiggles. Running \`tsc --noEmit\` passes. However, executing \`ts-node src/index.ts\` crashes with "Error: Cannot find module '@/config'". Compiling with \`tsc\` and running \`node dist/index.js\` produces the same error. Developer checks tsconfig 50 times, tries \`tsconfig-paths\`, but forgets to register it. Realizes that TypeScript's \`paths\` is compile-time only for type resolution; it does not rewrite import paths in the emitted JavaScript. Node.js module resolution knows nothing about tsconfig paths. The fix works because \`tsconfig-paths\` hooks into Node's \`Module.\_resolveFilename\` to read tsconfig paths at runtime, or a bundler rewrites the paths during the build step.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:11:13.345715+00:00— report_created — created