Microbundle: Export Default From Error

Created on 21 Jan 2020  路  11Comments  路  Source: developit/microbundle

First off, thank you for this package. I'm seeing an issue with the export default from '...' syntax which surprised me a little as I figure this pattern would be pretty common with library authors. For example, when I try to do the following:

export Base from './components/base.jsx'

I get the following babel output:

SyntaxError: /Users/greg/Desktop/projects/foundation-utils/src/lib.js: Support for the experimental syntax 'exportDefaultFrom' isn't currently enabled
...
Add @babel/plugin-proposal-export-default-from (https://git.io/vb4yH) to the 'plugins' section of your Babel config to enable transformation.

This brings two questions to mind....

  • Adding a .babelrc that specified that plugin didn't fix the issue. I'm guessing microbundle won't pick up a local babel config?
  • Since this is a fairly useful/common pattern for library authors, could we just add that plugin to microbundle by default?

There is a workaround, but obviously not a super pretty one:

import $Base from './components/base.jsx'

export const Base = $Base
needs more info wontfix

Most helpful comment

@Xiphe that's definitely a cleaner workaround, thanks! I did a little more research and found that it's still just a stage 1 proposal, so I guess I can understand _not_ supporting it given that there's a fairly simple workaround.

https://github.com/tc39/proposal-export-default-from
https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export

All 11 comments

I don't think this is a microbundle problem.

If you want to re-export the default, you should use

export { default } from './components/base.jsx';

What you're doing in the workaround is giving the default export a name. There is a shortcut for that:

export { default as Base } from './components/base.jsx';

@Xiphe that's definitely a cleaner workaround, thanks! I did a little more research and found that it's still just a stage 1 proposal, so I guess I can understand _not_ supporting it given that there's a fairly simple workaround.

https://github.com/tc39/proposal-export-default-from
https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export

@Xiphe good suggestion. I'm marking this as wontfix because I agree Microbundle doesn't need to support Stage-1 things, though I will admit I'm open to merging a PR that adds this to core. It's a feature most folks won't use, but it won't hurt anyone either.

@skipjack - adding a .babelrc should have worked - do you mind pasting what you had in there? Microbundle respects Babelrc for everything except node_modules.

I honestly was not aware of the export default from proposal. Thanks for letting me know 馃憤

Sure, just basically followed the instructions here:

__.babelrc__

{
  "plugins": [
    "@babel/plugin-proposal-export-default-from"
  ]
}

Are you on the latest microbundle version?

I'm on the latest stable version -- 0.11.0 -- I haven't tried microbundle@next yet though.

That shouldn't even have babel at all, we used buble before

I mean... it seems to be pulled from somewhere and I don't have it installed in this project. Meaning if I delete my .babelrc and the one babel dependency (@babel/plugin-proposal-export-default-from), I still get the following error (same as in my original question) which makes it seem like babel is being used somewhere under the hood of microbundle.

SyntaxError: /Users/greg/Desktop/projects/foundation-utils/src/lib.js: Support for the experimental syntax 'exportDefaultFrom' isn't currently enabled
...
Add @babel/plugin-proposal-export-default-from (https://git.io/vb4yH) to the 'plugins' section of your Babel config to enable transformation.

right, we had babel for async to promises

Closing given the workaround and responses.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

phryneas picture phryneas  路  12Comments

wcastand picture wcastand  路  16Comments

artemtam picture artemtam  路  19Comments

JoviDeCroock picture JoviDeCroock  路  17Comments

smithki picture smithki  路  19Comments