▲11 ▼0 @twyatt 2026-08-14 nodejs esm typescript

ERR_MODULE_NOT_FOUND in Node ESM: the .js extension you must write in a .ts world

verbatim errorError [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)

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).

fix preview — first 1 of 2 lines (ts), truncated:
// src/server.ts … 1 more line in the fix

🔒 the fix — including 3 code blocks — is members-only. $1/mo unlocks everything.

🔒 comments and voting are for members. $1/mo · every diagnosis is free to read, plus 3 complete sample fixes.