When can a CommonJS named export be imported by an ES module?

From the docs:

For better compatibility with existing usage in the JS ecosystem,
Node.js in addition [to the default import] attempts to determine the CommonJS named exports
of every imported CommonJS module to provide them as separate ES
module exports using a static analysis process.


The detection of named exports is based on common syntax patterns but
does not always correctly detect named exports. In these cases, using
the default import form described above can be a better option.

Named exports detection covers many common export patterns, reexport
patterns and build tool and transpiler outputs. See cjs-module-lexer
for the exact semantics implemented.

Read more here: Source link