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 default from' can not be correctly compiled #7293

Closed
leaves4j opened this issue Jan 30, 2018 · 12 comments · Fixed by #11676
Closed

'export default from' can not be correctly compiled #7293

leaves4j opened this issue Jan 30, 2018 · 12 comments · Fixed by #11676
Labels
claimed i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser Spec: export-default-from

Comments

@leaves4j
Copy link

Choose one: bug

Input Code

var from = 'test';
export default from;

Babel/Babylon Configuration (.babelrc, package.json, cli command)

{
  presets: [
        [
          '@babel/preset-env', {
            targets: { browsers: ['android>=4', 'ios>=7'] },
            modules: false,
          },
        ],
      ],
      plugins: [
        '@babel/plugin-transform-runtime',
      ],
}

Expected Behavior

Compiled correctly

Current Behavior

Throw an error

[!] (babel plugin) SyntaxError: /xxx/node_modules/@babel/runtime/core-js/array/from.js: Support for the experimental syntax 'exportDefaultFrom' isn't currently enabled (6:8):

  4 | var from = require$$0;
  5 |
> 6 | export default from;
    |        ^
  7 | export { from as __moduleExports };

Add @babel/plugin-proposal-export-default-from (https://git.io/vb4yH) to the 'plugins' section of your Babel config to enable transformation.
software version(s)
Babel 7.0.0-beta.38
Babylon
node 9.4
npm
Operating System mac os
@babel-bot
Copy link
Collaborator

Hey @leaves4j! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@nveenjain
Copy link
Contributor

nveenjain commented Jan 30, 2018

I think that's a bug in babylon. I'll look into it.

export default from;

This code should throw an Reference error as from is not defined (take it as separate example from your code), but rather it asks for additional(experimental) plugin to be added, which in turns does not accept this code either. Will try to solve and open a PR asap..

@nveenjain
Copy link
Contributor

@KFlash , i think this line is causing the error in babylon as this line in isExportDefaultSpecifier function does not consider the possibility that from might be lineTerminator..

@nveenjain
Copy link
Contributor

@KFlash , exactly, i was going to do the same.. I didn't know how V8, Esprima or SM implement it though. Thanks for the feedback..

@nveenjain
Copy link
Contributor

@KFlash , i've submitted a PR, would really appreciate review.

@vzaidman
Copy link

vzaidman commented Aug 29, 2018

also on 7.0.0 it seems like there is no way to make the following work:

export x from './y'

@FraBle
Copy link

FraBle commented Oct 21, 2018

@vzaidman did you find a solution?

@vzaidman
Copy link

i did many things and cant recall which of them helped.

make sure to use @babel/plugin-proposal-export-namespace-from.
make sure to upgrade babel-loader

sorry - no better advice

@johanazhu
Copy link

https://babeljs.io/docs/en/babel-plugin-proposal-export-default-from

@alex-cory
Copy link

@vzaidman do you think you could maybe post a snippet of your babel setup so we can see what presets/plugins you used and what babel dependencies you have to make everything work? Been stuck on this one for a little bit. I know order matters with some so that would also be helpful to see

@vzaidman
Copy link

not sure it's the best possible but still:
babel.config.js:

module.exports = function (api) {
  api.cache(true)

  return {
    presets: [
      ['@babel/preset-env', {
        useBuiltIns: 'entry',
        loose: true
      }],
      '@babel/preset-react'
    ],
    plugins: [
      '@babel/plugin-proposal-export-default-from',
      '@babel/plugin-proposal-export-namespace-from',
      '@babel/plugin-proposal-object-rest-spread',
      ['@babel/plugin-proposal-decorators', {legacy:true}],
      ['@babel/plugin-proposal-class-properties', {loose: true}]
    ]
  }
}

notice we use decorators so plugin-proposal-class-properties must be loose.

@helloanoop
Copy link

Adding the plugins '@babel/plugin-proposal-export-namespace-from' and '@babel/plugin-proposal-export-default-from' worked for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
claimed i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser Spec: export-default-from
Projects
None yet
9 participants