minify: Cannot read property 'add' of undefined
seeing " Cannot read property ‘add’ of undefined" with the latest
sample code, junk.js
const y = () => {};
function x(foo = y) {}
command: npx babel junk.js --presets=minify
package.json
{
"name": "babelbug",
"version": "1.0.0",
"description": "",
"devDependencies": {
"@babel/core": "^7.7.0",
"@babel/preset-env": "^7.7.0",
"@babel/cli": "^7.7.0",
"babel-preset-minify": "~0.5.0"
}
}
stack
{ TypeError: C:\babelbug\junk.js: Cannot read property 'add' of undefined
at ScopeTracker.addReference (C:\babelbug\node_modules\babel-plugin-minify-mangle-names\lib\scope-tracker.js:47:34)
at ReferencedIdentifier (C:\babelbug\node_modules\babel-plugin-minify-mangle-names\lib\index.js:196:26)
at newFn (C:\babelbug\node_modules\@babel\traverse\lib\visitors.js:220:17)
at bfsTraverse (C:\babelbug\node_modules\babel-plugin-minify-mangle-names\lib\bfs-traverse.js:32:43)
at Mangler.collect (C:\babelbug\node_modules\babel-plugin-minify-mangle-names\lib\index.js:229:7)
at Mangler.run (C:\babelbug\node_modules\babel-plugin-minify-mangle-names\lib\index.js:54:12)
at PluginPass.exit (C:\babelbug\node_modules\babel-plugin-minify-mangle-names\lib\index.js:558:19)
at newFn (C:\babelbug\node_modules\@babel\traverse\lib\visitors.js:179:21)
at NodePath._call (C:\babelbug\node_modules\@babel\traverse\lib\path\context.js:55:20)
at NodePath.call (C:\babelbug\node_modules\@babel\traverse\lib\path\context.js:42:17) code: 'BABEL_TRANSFORM_ERROR' }
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 19
- Comments: 23
Commits related to this issue
- Switch to using terser instead of babel Babel has this bug which appeared after trying to update to the latest version, and remained even after rolling back to an older version. Extremely annoying. ... — committed to fwextensions/QuicKey by fwextensions 3 years ago
- Release v1.6.1 Fix #57. Squashed commit of the following: commit d10eca3c60d70e6bfd52bcd451b81fd7f4146fe6 Author: John Dunning <fw@johndunning.com> Date: Tue May 4 15:54:50 2021 -0700 Update... — committed to fwextensions/QuicKey by fwextensions 3 years ago
I was able to work around this problem by using
@babel/plugin-transform-parameters
to transpile away the default parameters syntax prior to minification. I would still be interested to see the bug fixed though.The issue seems to be with default functional parameters set to a constant.
I see the same issue when using
rollup-babel-minify
. Dependabot tried to update to latest babel and couldn’t due to this issue.Seeing the same problem here… setting
mangle: false
in the options seems to work-around the problem.Any update? I found that it started to fail after a change in
@babel/types@7.8.0
- https://github.com/babel/babel/pull/10917 Hopefuly https://github.com/babel/minify/pull/1024 will be merged soon.Any update? Seem there is an PR checked but not merged.
I got same error.
Same issue here to build webtorrent