Node ESM compatibility issue
otakustay opened this issue · 2 comments
otakustay commented
When using dedent
in a node ESM environment, a import dedent from 'dedent'
statement will result a {default: dedent}
object.
> const dedent = await import('dedent')
undefined
> dedent`abc`
Uncaught TypeError: dedent is not a function
> dedent('abc')
Uncaught TypeError: dedent is not a function
> dedent
[Module: null prototype] {
__esModule: undefined,
default: <ref *1> [Function: dedent] { default: [Circular *1] }
}
> dedent.default`abc`
'abc'
This issue comes from several reasones:
- In
package.json
amodule
filed is specified todist/dedent.mjs
, but NodeJS doesn't support this field - The
main
field inpackage.json
references todist/dedent.js
which is a CommonJS module, NodeJS's ESM then transformsmodule.exports
into a default export
To address this, we need a exports
field in package.json
:
{
"exports": {
".": {
"types": "./index.d.ts",
"import": "./dist/dedent.mjs",
"default": "./dist/dedent.js"
}
}
}
This will solve the import issue, but is potentially a breaking change to NodeJS ESM environment, would it worse a major version?
JoshuaKGoldberg commented
Ah thanks for filing @otakustay! I think we can treat this as a bug and release as 1.2.0
/ minor version change. dedent.default
is a circular reference, so folks who were using it like dedent.default(...)
should generally not be broken.
JoshuaKGoldberg commented
Released as dedent@1.3.0
🚀