Skip to content
This repository has been archived by the owner on Jul 13, 2024. It is now read-only.

ES6 default export is an object with a "default" property #11

Open
4ur3-zut opened this issue Apr 18, 2023 · 1 comment
Open

ES6 default export is an object with a "default" property #11

4ur3-zut opened this issue Apr 18, 2023 · 1 comment

Comments

@4ur3-zut
Copy link

My team and I recently upgraded our project to ES6 import syntax for node imports. Setting "type": "module" in package.json.
This has changed the export behavior of Graphemer, and when it is imported, it's wrapped in an object:

import Graphemer from 'graphemer';
console.log(Graphemer);

> Graphemer = { default: <actual graphemer class> }

This happens in our webpack compile result, but also when using the node console directly:

> node
Welcome to Node.js v16.15.0.
Type ".help" for more information.
> import('Graphemer').then(console.log)
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 184,
  [Symbol(trigger_async_id_symbol)]: 170,
  [Symbol(destroyed)]: { destroyed: false }
}
> [Module: null prototype] {
  __esModule: true,
  default: { default: [class Graphemer] }
}

As you can see, 'default' is there twice.

Here's a temporary workaround:

const GraphemeSplitter = Graphemer?.default?.constructor instanceof Function ? new Graphemer.default() : new Graphemer();

It was working normally before setting "type": "module" in package.json.

@booc0mtaco
Copy link

FWIW in my case, we built our project using rollup, and in the consumer we saw this issue arise. We needed to set rollup to use interop: auto to add in TypeScript-equivalent shims to how the modules and dependencies were emitted. This solved the problem for us.

Related: rollup/rollup#2554

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants