babel-plugin-rewire icon indicating copy to clipboard operation
babel-plugin-rewire copied to clipboard

Compatibility with babel-plugin-transform-es2015-spread

Open NiallBrickell opened this issue 7 years ago • 11 comments

When using this plugin in addition to the es2015 preset, I'm getting:

Module build failed: TypeError: []: Cannot read property 'length' of undefined
    at hasSpread (.../node_modules/babel-plugin-transform-es2015-spread/lib/index.js:21:30)
    at PluginPass.CallExpression (.../node_modules/babel-plugin-transform-es2015-spread/lib/index.js:93:14)

on a lot of files. My config is:

{
  "presets": ["react", "es2015", "stage-0"],
  "plugins": ["lodash"],
  "env": {
    "test": {
      "plugins": ["rewire"]
    }
  }
}

Is this a known issue? Can't find anything on here.

NiallBrickell avatar Oct 31 '16 20:10 NiallBrickell

@NiallBrickell thanks for opening this issue and sorry for my delyed response as I was on hollidys over the last 3 weeks. I will have a look at your issue tomorrow in the evening and will then let you know how we will proceed with this bug.

speedskater avatar Nov 09 '16 09:11 speedskater

@NiallBrickell I tried to reproduce your error but could not get the same error you mentioned. Could you please create a small sample project I can checkout and investigate.

speedskater avatar Nov 10 '16 23:11 speedskater

@speedskater thanks for getting back & sorry for the late reply. Hope you enjoyed your holiday! Will make a small sample repo today.

NiallBrickell avatar Nov 16 '16 09:11 NiallBrickell

@NiallBrickell thanks for your answer. Any news on the sample repo?

speedskater avatar Nov 21 '16 09:11 speedskater

Sorry @speedskater it's taken me a while to get around to it - creating the repo now

NiallBrickell avatar Nov 21 '16 12:11 NiallBrickell

Can't reproduce the error :(

I'll keep trying to repro it. Sample repo at: https://github.com/NiallBrickell/rewire-es2015-example

NiallBrickell avatar Nov 21 '16 12:11 NiallBrickell

@speedskater I've managed to narrow it down to the placement of plugins in .babelrc when lodash is used for some reason. Ie, this works:

{
  "presets": ["react", "es2015", "stage-0"],
  "plugins": [
    "lodash",
    "istanbul",
    "babel-plugin-rewire",
  ],
}

but this doesn't:

{
  "presets": ["react", "es2015", "stage-0"],
  "plugins": [
    "lodash",
  ],
  "env": {
    "test": {
      "plugins": [
      ]
    }
  }
}

The line that affects this is reduce(test, (a, b) => a + b, ''); (from lodash). If this line isn't there, the placement of plugins doesn't matter.

NiallBrickell avatar Nov 22 '16 18:11 NiallBrickell

Any update on this @speedskater ?

NiallBrickell avatar Nov 29 '16 17:11 NiallBrickell

@NiallBrickell sorry for the delay. I had a look at your issue today. And I am able to reproduce it and also find a workaround by reordering the plugins to lodash, rewire instead of rewire, lodash. Sorry that this might be an unsatisfactory solution at the moment, but I think I won't be able to tackle this issue completly before the end of the year (but it won't be forgotten).

speedskater avatar Dec 12 '16 12:12 speedskater

I also bumped into this issue just now. My workaround is having "lodash" in both envs, so the plugins in test env are in the right order. Not pretty, but it works and doesn't seem to have any bad effects.

{
  "plugins": [
    "lodash"
  ],
  "env": {
    "test": {
      "plugins": [
        "lodash",
        "rewire"
      ]
    }
  }
}

tiepp avatar Feb 02 '17 13:02 tiepp

@tiepp thanks for reporting the workaround.

speedskater avatar Feb 13 '17 12:02 speedskater