Repository navigation
Closed
Labels
Description
Here's my .babelrc:
babelrc
{
"presets": [
"es2015", "stage-2", "stage-0", "react", "es2015-ie"
],
"plugins": [
"transform-runtime", "transform-decorators-legacy", "transform-class-properties"
],
"compact": true,
"env": {
"test": {
"plugins": ["istanbul"]
},
"production": {
"presets": [
"babili"
]
}
}
}
Running babel resulted in this error:
Details
ERROR in ./src/components/Main/index.js
Module build failed: TypeError: /src/components/Main/index.js: Cannot read property 'add' of undefined
at ScopeTracker.addReference (/node_modules/babel-plugin-minify-mangle-names/lib/scope-tracker.js:55:36)
at ReferencedIdentifier (/node_modules/babel-plugin-minify-mangle-names/lib/index.js:190:28)
at newFn (/node_modules/babel-traverse/lib/visitors.js:318:17)
at bfsTraverse (/node_modules/babel-plugin-minify-mangle-names/lib/bfs-traverse.js:34:43)
at Mangler.collect (/node_modules/babel-plugin-minify-mangle-names/lib/index.js:269:9)
at Mangler.run (/node_modules/babel-plugin-minify-mangle-names/lib/index.js:70:14)
at PluginPass.exit (/node_modules/babel-plugin-minify-mangle-names/lib/index.js:589:19)
at newFn (/node_modules/babel-traverse/lib/visitors.js:276:21)
at NodePath._call (/node_modules/babel-traverse/lib/path/context.js:76:18)
at NodePath.call (/node_modules/babel-traverse/lib/path/context.js:48:17)
at NodePath.visit (/node_modules/babel-traverse/lib/path/context.js:117:8)
at TraversalContext.visitQueue (/node_modules/babel-traverse/lib/context.js:150:16)
at TraversalContext.visitSingle (/node_modules/babel-traverse/lib/context.js:108:19)
at TraversalContext.visit (/node_modules/babel-traverse/lib/context.js:192:19)
at Function.traverse.node (/node_modules/babel-traverse/lib/index.js:114:17)
at traverse (/node_modules/babel-traverse/lib/index.js:79:12)
at File.transform (/node_modules/babel-core/lib/transformation/file/index.js:548:35)
at /node_modules/babel-core/lib/transformation/pipeline.js:50:19
at File.wrap (/node_modules/babel-core/lib/transformation/file/index.js:564:16)
at Pipeline.transform (/node_modules/babel-core/lib/transformation/pipeline.js:47:17)
at transpile (/node_modules/babel-loader/lib/index.js:46:20)
at Object.module.exports (/node_modules/babel-loader/lib/index.js:163:20)
@ ./src/dist.js 1:127-153
Now if I disable Mangling, the minification doesn't seem to have much effect:
Details
npm run dist
> BABEL_ENV=production webpack --env=dist
Hash: b6d52d6cc9478801536d
Version: webpack 1.15.0
Time: 4355ms
Asset Size Chunks Chunk Names
dist.js 749 kB 0 [emitted] main
dist.js.map 923 kB 0 [emitted] main
+ 340 hidden modules
Dist without production env:
Details
> webpack --env=dist
Hash: 8636992c125a9a4e5f8a
Version: webpack 1.15.0
Time: 3934ms
Asset Size Chunks Chunk Names
dist.js 752 kB 0 [emitted] main
dist.js.map 925 kB 0 [emitted] main
+ 340 hidden modules
Reacted by Bo Lingen, Griffin Yourick, Bohdan, Will Schurman 🦦, Vladimir Kudinov, Thomas K, Gilles Piou, Eric Cornelius, Boris Kirov, Anıl Anar and 40 more
Activity
boopathi commentedon May 24, 2017
Thanks. Do you have a minimal reproduction code snippet or the input code that creates this error ?
And since you're using webpack, can you try with babili-webpack-plugin to find if the same error happens with babili webpack plugin.
There are a few issues when used with es2015
joewilson81 commentedon May 26, 2017
I was having the same issue today, but I'm not using webpack.
It was working before some changes I had made, so I stashed them and re-applied them one by one. The culprit was the snippet below in a function that otherwise had no return value:
I can't show the client's code, but I'll try to put together an example later and see if I can reproduce the issue.
[-][SUPPORT] Cannot read property 'add' of undefined[/-][+][Bug] Cannot read property 'add' of undefined[/+][-][Bug] Cannot read property 'add' of undefined[/-][+][BUG] Cannot read property 'add' of undefined[/+]craftzdog commentedon May 31, 2017
I got same error with following code:
Making alias of
appresolved the error:Hope it helps.
boopathi commentedon May 31, 2017
Is everyone here facing this issue ONLY when using
babiliandes2015-block-scopingin the same transformation (or) both in babelrc ? (es2015-block-scoping is included inpreset-es2015orpreset-envwith a browser setting that convertslet/consttovar.)Is anyone getting the same bug when used WITHOUT es2015-block-scoping ?
craftzdog commentedon May 31, 2017
@boopathi
My .babelrc is:
{ "presets": [ "stage-0", ["env", { "targets": { "node": "7.4.0", "electron": "1.6.7" }, "useBuiltIns": true }] ], "plugins": [ "add-module-exports", "transform-decorators-legacy" ], "env": { "production": { "presets": ["babili"] } } }When I removed
preset-env, it worked.But below config with
transform-es2015-block-scopingalso worked:{ "presets": [ "stage-0" ], "plugins": [ "transform-es2015-block-scoping", "add-module-exports", "transform-decorators-legacy" ], "env": { "production": { "presets": ["babili"] } } }OR13 commentedon Jun 7, 2017
I am also experiencing this issue. My .babelrc
I can resolve it by turning mangle off:
jfurfaro commentedon Jun 8, 2017
I'm also having the issue, but only when transforming my source files with browserify. The second call to babili in gulp-babel doesn't error. Trying babili only in the browserify transform still errors. If I just disable mangle in the browserify transform, it works.
My gulp task
Add in post build step to minify code using UglifyJS
arichiardi commentedon Jun 20, 2017
So I have a repro repo: https://github.com/arichiardi/js.spec/tree/webpack-babili 😄
Just run
yarnandyarn run buildalcuadrado commentedon Jul 7, 2017
I'm having this same issue with this
.babelrc:jrencz commentedon Jul 11, 2017
I'm having the same issue. In my case it happens when there's a class and at least one method name is a symbol. If I switch from symbol to string (either computed or not) it works fine:
Fails:
Works:
Using: 0.1.3 (latest currently)
.babelrc
{ "presets": [ "latest", "stage-0", "babili", ], "plugins": [ "babel-plugin-add-module-exports" ] }39 remaining items
devongovett commentedon May 20, 2018
Just made a PR to work around the issue: #860. I'm not exactly sure why it happens - I'm not using the commonjs modules transform but it still happens for me. This seems to fix the issue though by just adding the missing scope before trying to track a reference in it.
LabhanshAgrawal commentedon Jan 13, 2020
@devongovett This error is occurring again, on updating to babel core 7.8.0
copyrighthero commentedon Jan 28, 2020
I'm upgrading babel from 7.7.4 to 7.8.3 today and this happened to me too, after changing the configuration for minify from
{mangle: true}to{mangle: false}I was able to build without problem; the name mangling is the issue for me too :-/arantes555 commentedon Feb 5, 2020
Same thing here. It seems to be happening again with 7.8, and seems it can be worked-around with
{mangle: false}eugenmihailescu commentedon Feb 10, 2020
In my case the same error occurred due to some function's parameter default value set to a constant.
The workaround was to replace the constant in the function declaration, like this:
or
somewhatabstract commentedon Feb 17, 2020
I am seeing this same error when using
rollup-babel-minify.ambroselittle commentedon May 20, 2020
This is still a problem today. @eugenmihailescu's workaround worked for me, which suggests that this plugin doesn't handle that correctly, even though it's valid. So it really should be re-opened and fixed (or a new issue).
Anyhow, I switched to terser, since that works for my sitch, and it handles using var/funcs to set default param values just fine.
cerinoligutom commentedon May 27, 2020
Encountered this today. @eugenmihailescu's workaround worked for me.
My scenario:
I'm using TypeScript and an enum value as the default value for a function parameter.
Did a bit of testing and found out it's not necessarily due to a
constantbut rather, as long as it's coming from a variable, it'll fail to transform.Drop bable minify for terser because of a build error.
Drop babel minify for terser because of a build error.
monokee commentedon Jun 16, 2020
It's still an issue. (rollup-babel-minify)
dimaqq commentedon Mar 1, 2021
Would it be better to reopen this issue or create new one?
ChenYCL commentedon Feb 22, 2022
same tody
Play nicely with buggy Babel implementations
Don't insert the same node into the AST multiple times (fixes babel/m…