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

babel-loader fails to compile properly with transform-object-rest-spread #496

Closed
NoiSek opened this issue Aug 3, 2017 · 3 comments
Closed

Comments

@NoiSek
Copy link

NoiSek commented Aug 3, 2017

I'm submitting a bug report

Webpack Version:
3.4.1

Babel Core Version:
6.25

Babel Loader Version:
7.1.1

Please tell us about your environment:
OSX 10.12.5

Current behavior:
Using the babel-loader loader with the transform-object-rest-spread plugin fails to compile properly:

ERROR in ./src/js/reducers/AppReducer.js
Module parse failed: /src/js/reducers/AppReducer.js Unexpected token (2:10)
You may need an appropriate loader to handle this file type.
| let a = { 'x': 1, 'y': 2 };
| let b = { ...a, 'z': 3 };
|
| console.log(b);
 @ ./src/js/application.js 4:0-51

Expected/desired behavior:
Webpack should compile with the transform-object-rest-spread plugin properly, as it does when invoked manually:

λ ./node_modules/.bin/babel src/js/reducers/AppReducer.js
'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var a = { 'x': 1, 'y': 2 };
var b = _extends({}, a, { 'z': 3 });

console.log(b);

Relevant portion of webpack.config.js:

'module': {
    'rules': [
        {
            'test': /\.(js|jsx)$/,
            'include': [
            ],
            'use': [
                'babel-loader'
            ]
        }
    ]
}

.babelrc

{
    'presets': ['es2015'],
    'plugins': [
      'transform-object-rest-spread'
    ]
}

Relevant portion of `package.json``

{
  "dependencies": {
    "babel-cli": "^6.24.1",
    "babel-core": "^6.25.0",
    "babel-loader": "^7.1.1",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "webpack": "^3.4.1"
  }
}

Strongly inclined to believe that babel-loader itself is the source of the issue, as files appear to compile normally when babel is manually invoked (see above).

Removing the transform-object-rest-spread plugin and adding the stage-3 preset (which contains the object rest spread proposal) also appears to have no effect. Force upgrading and re-installing all of the above dependencies appears to have no effect either.

Is this a known issue? Searching around, it seems that many others seem to run into the same problem and are rarely able to solve it.

@loganfsmyth
Copy link
Member

Doesn't 'include': [] literally say "don't process any files" with Babel?

@NoiSek
Copy link
Author

NoiSek commented Aug 3, 2017

Huh. Normally that include has a few path.resolve lines present (ostensibly to add a few directories to the PATH), but that isn't how include works, and beyond that, include doesn't work the way I would have guessed it did in the first place now that I'm examining it.

Removing the include here entirely appears to solve the issue, although I have no idea how this ever compiled in the first place if what it really meant was that it ONLY applied those rules to the files in 'X' directories.

Does Webpack have some inferred ES6 transpilation built in?!

@NoiSek NoiSek closed this as completed Aug 3, 2017
@loganfsmyth
Copy link
Member

You're probably testing your code in an environment that supports ES6. Object-spread isn't standard yet, so Webpack can't process it, but any standardized syntax will pass through Webpack into the output file with no problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants