Skip to content

module: support __cjsUnwrapDefault interop flag in require(esm)

Rodrigo Muino Tomonari requested to merge github/fork/guybedford/cjs-unwrap into main

This adds support for export const __cjsUnwrapDefault = true in a CJS module to imply that the default export should always be used as the module value when requiring that ESM module under require(esm), allowing other types than just module namespaces in this interop.

This effectively splits off the non-major change from https://github.com/nodejs/node/pull/53848 as discussed in the Node.js loaders meeting, under a rename of __cjsModule to __cjsUnwrapDefault, where that PR will be updated to use the name that lands here on the ESM wrapper as a major change further.

The naming bikeshed is taking place in https://github.com/nodejs/loaders/issues/221. Note that all naming-related comments should only be posted there further.

//cc @nodejs/loaders

Merge request reports

Loading