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

Consider supporting __esModule flag on CommonJS #496

Closed
guybedford opened this issue Feb 5, 2016 · 5 comments
Closed

Consider supporting __esModule flag on CommonJS #496

guybedford opened this issue Feb 5, 2016 · 5 comments

Comments

@guybedford
Copy link
Contributor

CommonJS modules that have the defineProperty(exports, '__esModule', { value: true }) thing could potentially be inferred as ES modules automatically in Rollup, and their exports bindings treated as such. Almost a sort of reverse CommonJS -> ES6 transformation. This would allow any modules transpiled with Babel into CommonJS to support Rollup optimizations due to their bindings nature.

This would greatly improve Rollup's ability to inline modules, as a sort of alternative to the jsnext:main thing.

Just sending the idea along though, feel free to close.

@Victorystick
Copy link
Contributor

It's a good idea, for sure. More npm modules are available as CommonJS processed by Babel than are proper ES modules. See rollup/rollup-plugin-commonjs#10, rollup/rollup-plugin-commonjs#16 and rollup/rollup-plugin-commonjs#29 for some Babel/CommonJS related issues.

This issue, if handled, should probably be done by the CommonJS plugin. Or an un-babel plugin, that assumes it's working with code that used to be proper ES modules.

@fregante
Copy link

Not only supporting, but also exporting it. My CJS rollup exports are not being recognized correctly by babel because its version of _interopDefault only checks for the __esModule property.

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

Source: https://github.com/babel/babel/blob/5b89849f432cfc034860f495b5001039123e7754/packages/babel-helpers/src/helpers.js#L238-L242

@Nathan-Wall
Copy link

I'm trying to set up a system where I can write code using ES2015 modules, transform to AMD for development, and Rollup to a bundle for deployment. Having Rollup, Babel, and RequireJS understand each others output better would be helpful for me. I think this would be a good step.

@eventualbuddha
Copy link
Contributor

Rollup does now output this flag. Whether the CommonJS plugin handles it specially I don't know.

@Rich-Harris
Copy link
Contributor

Will close this as recent versions of rollup-plugin-commonjs handle transpiled modules

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

6 participants