← All tasks
javascriptdmnd/dedent #58Not a task: not reproduced

Node ESM compatibility issue

envgap__dmnd__dedent-58

01 / FAILURE SIGNATURE

As reported upstream

Uncaught TypeError: dedent is not a function
Not a benchmark task.
  • In a clean container the reported failure did not reproduce, or the known fix did not make the project run.

02 / ENVIRONMENT RECIPE

Base commit
90047293fd50107c05900b76b4b23e9d4d6e7a4d
Manifest
package.json
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

dmnd/dedent #58 · read the original issue
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: 



1. In `package.json` a `module` filed is specified to `dist/dedent.mjs`, but NodeJS doesn't support this field

2. The `main` field in `package.json` references to `dist/dedent.js` which is a CommonJS module, NodeJS's ESM then transforms `module.exports` into a default export



To address this, we need a `exports` field in `package.json`:



```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?
Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]