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

Export syntax creates duplicate default exports #205

Closed
jxnblk opened this issue Jul 28, 2018 · 4 comments
Closed

Export syntax creates duplicate default exports #205

jxnblk opened this issue Jul 28, 2018 · 4 comments
Labels
🐛 type/bug This is a problem

Comments

@jxnblk
Copy link
Contributor

jxnblk commented Jul 28, 2018

Using the following syntax for layouts causes a syntax error (SyntaxError: Only one default export allowed per module.):

export { default } from './Layout'
@silvenon
Copy link
Contributor

silvenon commented Sep 21, 2018

Just to expand upon this a bit.

The code snippet above is a way to make a default export using named exports. There are other variants of this, like:

// exporting directly from a module
export { Layout as default } from './components'
// exporting a variable
import Layout from './components'
export { Layout as default }
// bundled with other exports
export { Layout as default, meta } from './post-components'

etc. AFAICT, this isn't a simple regex fix because we need convert things like this:

export { default } from './Layout'

into something like this:

import Layout from './Layout'

export default ({ components, ...props }) =>
  <MDXTag name="wrapper" layout={Layout} ...

which means that we need to pick a name which doesn't collide with existing variable names etc.

I think we need to bring in Babel parser for this.

@timneutkens
Copy link
Member

I'm strongly against bringing Babel into mdx to solve just one issue.
The question would be if we really need to support all these edge cases and extra JS syntax if it can be achieved another way.

@silvenon
Copy link
Contributor

silvenon commented Sep 21, 2018

As a maintainer I'm against it as well, but I can see why people would expect this to work. I can submit a PR which raises an error upon encountering this syntax.

@jxnblk
Copy link
Contributor Author

jxnblk commented Sep 21, 2018

I agree with keeping Babel out of mdx. I mostly just wanted to share that I noticed that that particular syntax doesn't seem to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 type/bug This is a problem
Development

No branches or pull requests

3 participants