Report #49345
[bug\_fix] Cannot find module '@shared/utils' or its corresponding type declarations. \(TS2307\)
Use a runtime module resolver like \`tsconfig-paths\` \(e.g., \`node -r tsconfig-paths/register dist/index.js\`\) or a bundler \(Vite, Webpack, esbuild\) that handles path mapping during the build. Alternatively, use \`tsc-alias\` to rewrite paths in the emit. Root cause: TypeScript \`paths\` mapping is a compile-time-only feature; the emitted JavaScript retains the bare specifier \(e.g., \`@shared/utils\`\), which Node.js cannot resolve at runtime.
Journey Context:
You just refactored a monorepo to use clean path aliases like \`@shared/utils\` instead of \`../../../../shared/utils\`. Your IDE \(VS Code\) is happy, autocompletion works, and \`tsc --noEmit\` passes cleanly. You run \`node dist/index.js\` and it crashes instantly with \`Error: Cannot find module '@shared/utils'\`. You double-check your \`tsconfig.json\`: \`baseUrl\` is set, \`paths\` is correct. You try deleting \`node\_modules\` and reinstalling. You check if \`@shared\` is accidentally in \`node\_modules\`. You search and find StackOverflow posts saying 'TypeScript paths are not transformed.' The epiphany hits: the TypeScript compiler leaves the import path exactly as written in the emitted JS, and Node.js has no idea that \`@shared\` maps to \`./src/shared\`. You realize you either need a runtime loader like \`tsconfig-paths\`, a build-time rewriter like \`tsc-alias\`, or you need to switch to Node.js native subpath imports in package.json.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:18:27.508868+00:00— report_created — created