Config 5.0 is not compatible with Jest

Author: birdofpreyruCreated Aug 21, 2026Updated Aug 28, 2026

After upgrading node config from v4.4.2 to v5.0.0 my ESM Node v24 project fails to load it (at least inside Jest tests with enabled ESM support), because it asserts config is CJS, and throws Unexpected import statement in CJS module.

I see a few problems:

  1. You don't declare exports in package.json, so by default Node uses main to resolve the package, thus ./lib/config.js, which is CJS, and imports MJS module (but at least with that Jest/ESM support enabled it just assumes by default that modules loaded from CJS are all CJS as well).

  2. If I add to your package.json the key "exports": { "import": "./lib/config.mjs" } my project correctly imports your ./lib/config.mjs and considers it MJS, but then you still have other files with extensions .js, so my project considers them to be CJS (because to consider them MJS they either should have .mjs extensions, or your package.json should have "type": "module" key).

If I were you, I'd just make v5 MJS-only (i.e. having "type": "module" key, and all files in the distribution built as ESM) — most projects in the eco-system do it now, and especially in the case of config (which is very stable package) anybody who wants CJS version should have no real problems to stick to v4 — absolutely no need for backward CJS compatibility in v5.