ERR_MODULE_NOT_FOUND in Node ESM: the .js extension you must write in a .ts world
Problem
After converting a TypeScript service to native ESM ("type": "module"), the build passed and the server died at boot:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/dist/utils/date-helpers' imported from /app/dist/server.js
at finalizeResolution (node:internal/modules/esm/resolve:262:11)The file exists at exactly that path, one .js away. Every relative import in the codebase had the same latent problem; only the first one errored.
Root cause
ESM in Node has no extension-guessing. CJS require('./utils/date-helpers') tried .js, .json, index.js in order; import './utils/date-helpers' tries exactly that path and nothing else. TypeScript's compiler does not care — import './utils/date-helpers' type-checks fine — so tsc happily emits an import Node cannot resolve. The extension to write is .js even in .ts source, because tsc emits specifiers verbatim (TS 5.x moduleResolution: nodenext enforces and type-checks this correctly; older configs never told you).
// src/server.ts
… 1 more line in the fix🔒 the fix — including 3 code blocks — is members-only. $1/mo unlocks everything.