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
mixed default and named exports not working in cjs and umd #264
Comments
Made PR #265 to fix this. There unfortunately isn't a workaround for keeping both named and default exports. |
What do you mean? AFAIK the workaround is to use the |
@FezVrasta during the bundling process |
Sorry I don't think I understand :-( |
it's supposed to be an optimization for libraries that do this: export { foo, bar, baz };
export default { foo, bar, baz }; Normally, that would result in the following commonjs output: module.exports = { foo, bar, baz };
Object.defineProperty(module.exports, '__module', { value: true });
module.exports.default = { foo, bar, baz }; |
we really shouldn't handle that |
I also think this is not needed, why anyone is doing this and why we’d like to strip named exports? If we plan to support this (given there is some reason to do so) then the heuristic should be tweaked - it should only happen when exported namespace has the same shape as object exported as default |
@Andarist agreed! Is there a way to hook into Rollup and actually see what the exports are? Perhaps an AST plugin that just looks for the duplicative exports on the entry module... @ForsakenHarmony It's something from a fairly long time ago, maybe not needed really these days now that ES Modules usage is both more common and less Babel-specific. I'd still like a way to output the optimal commonjs/umd bundle while catering to the ES Modules hack, but I could also potentially do that using a second entry module. |
Not at the time we want it, thanks to static shape of ESM it should be really easy to implement this as custom plugin using transform hook and babel in it.
IMHO it would be better to implement support for different entries per format (using convention like |
I'm okay with removing the pruning I guess. For the couple cases I rely on it I can just use |
265: Remove import pruning r=ForsakenHarmony a=marvinhagemeister Fixes #264 **EDIT:** PR #262 likely needs to be merged first, as that one fixes the failing CI. Co-authored-by: Marvin Hagemeister <marvin@marvinhagemeister.de> Co-authored-by: Jason Miller <developit@users.noreply.github.com> Co-authored-by: Leah <me@hrmny.sh>
Hey everyone! I am having the same issue, if I export like this: import GoogleMap from './google_map';
export default GoogleMap; It will build: module.exports = GoogleMap; However, when including named exports, it changes to: exports.namedExport = namedExport;
...
exports.default = GoogleMap; |
if you try to bundle this, the result is:
I'd expect:
it exports everything only on the
esm
build.Is there any flag to turn on?
The text was updated successfully, but these errors were encountered: