Skip to content

Importing an ES Module doesn't import the default export #872

@jacques-blom

Description

@jacques-blom

Expected Behavior

react-outside-click-handler is an ES module package that is built to CJS. It sets the __esModule property on its exports (see here).

So when I import it (import OutsideClickHandler from "react-outside-click-handler") with the help of @rollup/plugin-commonjs, I'd expect OutsideClickHandler to be the module's default export.

My assumption is based on the behaviour mentioned in #481.

Actual Behavior

Importing the module returns the whole namespace:

import OutsideClickHandler from "react-outside-click-handler"

/*
OutsideClickHandler is...
{
  default: [Function: OutsideClickHandler] {
    propTypes: {
      children: [Function: bound checkType],
      onOutsideClick: [Function: bound checkType],
      disabled: [Function],
      useCapture: [Function],
      display: [Function],
      'prop-types-exact: ​': [Function]
    },
    defaultProps: { disabled: false, useCapture: true, display: 'block' }
  }
}
*/

Additional Information

I have tried various combinations of the plugin's options but the behaviour is always the same.

The entry point for react-outside-click-handler is this file, which doesn't define __esModule. Is that where it's missing?

Others have experienced this with ViteJS but the packages mentioned there don't define __esModule.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions