Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@rollup/plugin-commonjs: Named import is undefined from UMD module with default export #409

Closed
BryceMehring opened this issue May 24, 2020 · 2 comments

Comments

@BryceMehring
Copy link

  • Rollup Plugin Name: @rollup/plugin-commonjs
  • Rollup Plugin Version: 12.0.0
  • Rollup Version: 2.10.8
  • Operating System (or Browser): Browser
  • Node Version: 12.16.1

How Do We Reproduce?

https://repl.it/repls/EasygoingStudiousFeed

Rollup version 2.3.4 and onward seems to be causing the issue. Rollup version 2.3.3 does not have the issue and the code works as expected. The reproduction link uses the latest version of rollup and the commonjs plugin. Similar to #400

Expected Behavior

Named imports from UMD modules with a default export should resolve to the correct variable.

Actual Behavior

Named imports are resolving from the default export which in this case is undefined.

@danielgindi
Copy link
Contributor

This is the exact same issue as #400.
Please refer to my reply there and read carefully. Following the links is also recommended.
The gist of it - we follow the babel standard with __esModule export for interop between CJS and ESM. It does not support both named exports and default export, and there's no good choice between them.

So there are two ways to do this correctly,

  1. Add the named exports over the defaults exports too - to make them compatible (also with webpack and other packers). This is what most people do.
  2. Use destructured require combined with feature(commonjs): support for destructuring require for named imports #414

@shellscape
Copy link
Collaborator

Closing in favor of #400.

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

No branches or pull requests

4 participants