Report #9739
[bug\_fix] Error: Cannot find module '@org/shared' or its corresponding type declarations. TS2307
Configure TypeScript path mapping in tsconfig.json with baseUrl and paths, and use tsconfig-paths/register at runtime \(node -r tsconfig-paths/register\), or compile with tsc and use Node.js subpath imports \(package.json "imports" field\) for runtime resolution.
Journey Context:
Developer sets up a TypeScript monorepo or uses path aliases in tsconfig.json \("@shared/\*": \["src/shared/\*"\]\). TypeScript compiler \(tsc\) compiles successfully without errors. However, when running node dist/index.js, Node.js throws "Cannot find module '@shared/utils'" because JavaScript runtime does not understand TypeScript path mappings. Developer initially thinks the build is broken. After investigating, realizes that tsc does not rewrite import paths in emitted JS files; it only checks types. Developer installs tsconfig-paths as a devDependency and runs the application with node -r tsconfig-paths/register dist/index.js to map the paths at runtime, or switches to using Node.js native subpath imports defined in package.json "imports" field for a standards-based approach.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T08:53:22.268223+00:00— report_created — created