-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Spread Operator bug? #5548
Comments
@damianobarbati Object rest/spread operators are not in spec yet (stage-3) and are not supported by acorn out of the box. It's not a bug. Use some babel require hook. |
@TrySound but babel compiles fine, no error thrown by the parser so far. How can this be? |
@damianobarbati Babel is transpiller. It supports a lot of future things. Webpack uses acorn, which is not babel. |
Oh thanks for clarifying I didn't know this. But shouldn't webpack use |
You should use babel-loader to transpile such things. |
Check that you have babel plugin which enables spread operator. |
Of course @TrySound! The entire react project is processed through babel-loader.
|
As I said spread operator is stage-3. So you don't have it in your config. Please, help yourself and use such plugins directly. stage presets are changed too often. |
But stage-0 includes stage-1, 2 and 3 https://babeljs.io/docs/plugins/preset-stage-0/ I'll try tomorrow using individual plugins as you suggest. |
You are right. Show webpack config. |
This is it => https://github.com/damianobarbati/react-app/blob/master/config/webpack.config.js I can confirm the problem is only for npm-linked modules. |
You probably excluded it from babel-loader rule |
Bingo: I forgot |
One should re-consider that. As of November 2017, everything else in the chain besides webpack (i.e. firefox, node, babel, uglifyJS) supports object spread operator. I got to this problem only when I started to use Webpack. What should I do if my browser supports object spread operator? I don't want Babel to transpile that. I want to receive |
I see that it is not supported by |
Could you use https://github.com/victor-homyakov/acorn-object-rest-spread ? |
By the way, it is Stage 3 proposal now https://github.com/tc39/proposals/blob/master/README.md Stage 3 means "Candidate", i.e. close to be accepted. |
How could I go about making my webpack use acorn-object-rest-spread? Is there a config option or something? |
acorn now supports it acornjs/acorn#388 |
Does it mean that the next release of acorn and then webpack will handle it? |
The webpack parser will need to be updated to handle the syntax as well, since it has special-case code for each node type. I recently wrote a (hacky) webpack plugin that patches the parser to handle the syntax, so the updated "walk" functions in the code are approximately what will need to be changed. But it should be an easy fix, I think. https://github.com/alangpierce/sucrase/tree/master/integrations/webpack-object-rest-spread-plugin |
It is fully accepted now as far as I can tell, and this is still an issue for my projects even with all my dependencies fully updated (using webpack 4.0.0) |
Thanks a lot @alangpierce ! |
@Darkrender I hit this too (with webpack 4.5.0), and after slamming my head against trying to create a minimal reproduction of it I eventually fixed it by removing node_modules and |
but still using
|
The thing that's strange to me is that some of us have acorn |
Are you using yarn or npm lock? My problem went away with a clean install, which implies there's some deep dependency of webpack - but if it's not acorn, what is it? |
I'm using But I think it can be caused even with the right acorn. I have another project where it didn't matter what version |
And |
It shows webpack is using acorn 5.5 (what I'm doing is building handsontable with babel loader removed, compile with
|
It also shows webpack using |
webpack upgraded |
Hmm, though webpack has had an acorn@^5.0.0 dep since 2.4.0, so it's probably just that you're still on webpack 3. Just tested and yarn 1.6.0 correctly updated the transitive acorn going from webpack 3 to 4. |
@damianobarbati could you please speficy what you needed to add exactly? I am having the exact same issue, ES6 spread fails for linked node_modules. But why (and where) did you need to set |
@klimashkin thanks, Removing the acorn lines in
|
Same issue for me. Deleted my |
Bug.
I'm requiring a file with the following statement (using
require
because I'll be using both on node and browser):The working
complexUser
:The NOT working
complexUser
:Error thrown by Webpack:
Both babel and node do not complain if running the file directly (https://goo.gl/E3ZSEq).
The text was updated successfully, but these errors were encountered: