Config 5.0 is not compatible with Jest
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:
You don't declare
exportsinpackage.json, so by default Node usesmainto 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).If I add to your
package.jsonthe key"exports": { "import": "./lib/config.mjs" }my project correctly imports your./lib/config.mjsand 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.mjsextensions, or yourpackage.jsonshould 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.
Source: node-config/node-config