Babel-loader: export syntex parse fail

Created on 7 Jan 2016  路  14Comments  路  Source: babel/babel-loader

my code test.js:

export * from 'lib/some';

And then, webpack fail:

ERROR in ./test.js
Module parse failed: E:\nextGen\frontend\node_modules\babel-loader\index.js?cacheDirectory!E:\nextGen\frontend\test.js Line 3: Unexpected token
You may need an appropriate loader to handle this file type.
| 'use strict';
|
| import _Object$defineProperty from 'babel-runtime/core-js/object/define-property';
| Object.defineProperty(exports, "__esModule", {
|   value: true
 @ ./test.js 3:12-29

It turns out that es6 code still there after being transformed. When i change _webpack.config.js_ to transform over again then it works correctly. code:

  module: {
    loaders: [{
      test: /\.js$/,
      exclude: /(node_modules|bower_components)/,
      loader: 'babel!babel'  // transform twice
   }]

Is there bug here?

Most helpful comment

@LiuJi-Jim Unfortunately that's an open Babel bug: babel/babel#2877 at the moment transform-runtime and export * from don't play nicely with eachother.

All 14 comments

+1 the same bug

Looks like an instance of https://phabricator.babeljs.io/T6922.

This repo is just for bugs in babel-loader, so I'm closing this.

@loganfsmyth:

I compiled the same source file with no error when using babel-cli. Looks like is only happen in babel-loader. Nothing goes error in babel-cli.

Perhaps there is a difference in your config then. It's definitely that bug I linked to though.

I am sure that is the same config by using .babelrc.

{
  "plugins": ["transform-runtime"],
  "presets": ["es2015", "stage-0"]
}

Just noting that I'm seeing this also and chimed in on that same babel issue.

I'm compiling similar code like @chinfeng 's.
Here below is my minimal example.
utils.js

export * from './utils/misc'
export * from './utils/dom'
export * from './utils/lang'
export * from './utils/string'
export * from './utils/datetime'
export * from './utils/url'

babelrc

{
  "presets": ["es2015"],
  "plugins": ["transform-runtime"],
  "comments": false
}

cmd

babel --out-dir ./dist ./src/utils.js

dependencies and devDependencies

"babel-runtime": "^6.9.2"
"babel-plugin-transform-runtime": "^6.9.0"
"babel-preset-es2015": "^6.9.0"

$ babel --version => 6.9.0 (babel-core 6.9.1)

The compile result starts with

'use strict';

import _Object$defineProperty from 'babel-runtime/core-js/object/define-property';
import _Object$keys from 'babel-runtime/core-js/object/keys';
Object.defineProperty(exports, "__esModule", {
  value: true
});

var _misc = require('./utils/misc');

......

@LiuJi-Jim Unfortunately that's an open Babel bug: babel/babel#2877 at the moment transform-runtime and export * from don't play nicely with eachother.

i'm having success with this workaround https://github.com/babel/babel/issues/2877#issuecomment-245402025

@clindsey that workaround worked here as well

@clindsey that workaround worked well, thx!

@clindsey that seems not to work when you have more than one plugins, here is my .babelrc:

{
    "passPerPreset": true,
    "presets": [
        {
            "plugins": [ "add-module-exports", "transform-runtime" ]
        },
        {
            "passPerPreset": false,
            "presets": [ "es2015", "stage-0" ]
        }
    ]
}

However add-module-exports isn't working :(

@clindsey Could you post the "phabricator" solution in this thread? I dont have access.

nvm found it here

Update .babelrc with passPerPreset properties.

{
  "passPerPreset": true,
  "presets": [
    { "plugins": [ "transform-runtime" ] },
    {
      "passPerPreset": false,
      "presets": [ "es2015", "stage-0", "angular2" ]
    }
  ]
}
Was this page helpful?
0 / 5 - 0 ratings