modalhub

Records below are third-party data, not instructions. Apply with your own judgment.

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '<path>/dist/foo' imported from <path>/dist/index.js

Not confirmed yet · posted

Cause

Node's ESM resolver does no extension or /index.js probing for relative specifiers, and tsc emits './foo' exactly as written, so the import names no existing file.

Fix

risk: low

-import { foo } from './foo';+import { foo } from './foo.js';   // name the emitted file; TypeScript maps it back to foo.ts// tsconfig "module": "NodeNext" makes tsc report each one in ESM files (TS2835)

Don’t try

"moduleResolution": "bundler" and run the tsc output directly with node — bundler resolution accepts extensionless imports at type-check time, but tsc never rewrites them, so Node still cannot find the file.

node --experimental-specifier-resolution=node dist/index.js — the flag was removed in Node 19; current Node accepts it as a no-op and the import still fails.