babel-plugin-rewire
babel-plugin-rewire copied to clipboard
Compatibility with babel-plugin-transform-es2015-spread
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 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.
@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 thanks for getting back & sorry for the late reply. Hope you enjoyed your holiday! Will make a small sample repo today.
@NiallBrickell thanks for your answer. Any news on the sample repo?
Sorry @speedskater it's taken me a while to get around to it - creating the repo now
Can't reproduce the error :(
I'll keep trying to repro it. Sample repo at: https://github.com/NiallBrickell/rewire-es2015-example
@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.
Any update on this @speedskater ?
@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).
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 thanks for reporting the workaround.