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

Building @babel/standalone fails on commonjs@15 #557

Closed
JLHwung opened this issue Aug 26, 2020 · 5 comments
Closed

Building @babel/standalone fails on commonjs@15 #557

JLHwung opened this issue Aug 26, 2020 · 5 comments

Comments

@JLHwung
Copy link
Contributor

JLHwung commented Aug 26, 2020

Rollup Config: https://github.com/JLHwung/babel/blob/95dc47882afbe98064f90420108f69b35b070f4a/Gulpfile.js#L123-L164

make bootstrap

Expected Behavior

Build all babel artifacts.

Actual Behavior

throws

Error: 'default' is not exported by rollupPluginBabelHelpers.js, imported by node_modules/chalk/templates.js

See https://github.com/JLHwung/babel/runs/1033102860#step:6:573 for the error logs.

Additional Information

I believe it is an integration issue between @rollup/plugin-babel and @rollup/plugin-commonjs: The plugin-babel serves a virtual file rollupPluginBabelHelpers.js via the load hook. It is am ESM moudle generated from @babel/core. So I guess what happens here is the babel helper is added to the chalk/templates (because of for-of helpers) but for some reason transformed as require when Rollup is processing. On reading https://github.com/rollup/plugins/tree/master/packages/commonjs#esmexternals, it seems that I should specify esmExternals, so I tried add to commonjs the following options.

esmExternals: ["\0rollupPluginBabelHelpers", "rollupPluginBabelHelpers"]

But the build still fails. Even in the end esmExternals works for this virtual file, it feel like a hack and I hope it can be processed by @rollup/plugin-babel.

Another issue may be related: I tried downgraded commonjs@14 but our standalone test fails: https://github.com/babel/babel/runs/1033085554#step:10:128 I haven't investigate yet.

As a workaround we are pinning commonjs to 13: babel/babel#12010

@lukastaegert
Copy link
Member

Would it be possible to boil this problem down to have a reproduction that only contains few files and as few plugins as possible and directly calls Rollup? esmExternals sounds like it does not apply here anyway because it only applies to files that are NOT bundled? Fiddling with requireReturnsDefault sounds like more of an option, but it is false by default meaning it should not cause issues here.

@JLHwung
Copy link
Contributor Author

JLHwung commented Oct 2, 2020

@lukastaegert Sorry for the late reply. Here is a reproduction repo: https://github.com/JLHwung/rollup-plugin-issue-557

It bails when a babel option sourceType: "unambiguous" is configured. So it involves how Babel play with @rollup/plugin-babel. I will see if there is any I can do on Babel side.

@lukastaegert
Copy link
Member

Did you try version 15.1.0 of the commonjs plugin?

@JLHwung
Copy link
Contributor Author

JLHwung commented Oct 2, 2020

@lukastaegert The reproduction repo uses 15.1.0.

@stale stale bot added the x⁷ ⋅ stale label Dec 1, 2020
@stale
Copy link

stale bot commented Dec 2, 2020

Hey folks. This issue hasn't received any traction for 60 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it.

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

3 participants