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' }
I have the same error with this code:
const defaultLib = require('./default-lib');
foo(lib = defaultLib) {
this.lib = lib;
}
The issue seems to be with default functional parameters set to a constant.
Seeing the same problem here... setting mangle: false in the options seems to work-around the problem.
Also, seems there is a similar old issue : https://github.com/babel/minify/issues/556
I see the same issue when using rollup-babel-minify. Dependabot tried to update to latest babel and couldn't due to this issue.
TypeError: unknown: Cannot read property 'add' of undefined
at ScopeTracker.addReference (/Users/jeffyates/git/checksync/node_modules/babel-plugin-minify-mangle-names/lib/scope-tracker.js:47:34)
at ReferencedIdentifier (/Users/jeffyates/git/checksync/node_modules/babel-plugin-minify-mangle-names/lib/index.js:196:26)
at newFn (/Users/jeffyates/git/checksync/node_modules/@babel/traverse/lib/visitors.js:220:17)
at bfsTraverse (/Users/jeffyates/git/checksync/node_modules/babel-plugin-minify-mangle-names/lib/bfs-traverse.js:32:43)
at Mangler.collect (/Users/jeffyates/git/checksync/node_modules/babel-plugin-minify-mangle-names/lib/index.js:229:7)
at Mangler.run (/Users/jeffyates/git/checksync/node_modules/babel-plugin-minify-mangle-names/lib/index.js:54:12)
at PluginPass.exit (/Users/jeffyates/git/checksync/node_modules/babel-plugin-minify-mangle-names/lib/index.js:558:19)
at newFn (/Users/jeffyates/git/checksync/node_modules/@babel/traverse/lib/visitors.js:179:21)
at NodePath._call (/Users/jeffyates/git/checksync/node_modules/@babel/traverse/lib/path/context.js:55:20)
at NodePath.call (/Users/jeffyates/git/checksync/node_modules/@babel/traverse/lib/path/context.js:42:17)
Same issue here.
same issue here :(
Same issue here to build webtorrent
I'm having the same issue when I'm assigning a default value to a parameter. As soon as I remove the default value, the issue is gone.
Same issue
I have noticed a weird behaviour :
@babel/[email protected], and I do not hit this issue@babel/core to any superior version, I start hitting the issue@babel/core to 7.5.5, I still hit the issue.I think this means the issue is caused by one of @babel/core's dependencies. Not sure how to pinpoint which one :/
Same issue here.
same issue :(
The issue seems to be with default functional parameters set to a constant.
Same for me on both babel-preset-minify 0.4.3 and 0.5.1.
This doesn鈥檛 compile:
import { doc } from '../utils/Document';
const DEFAULT_DEBOUNCE_DELAY = 100
let resizeTimer = null
export default function debounceResize(callback, delay = DEFAULT_DEBOUNCE_DELAY) {
clearTimeout(resizeTimer)
doc.classList.add('resizing')
resizeTimer = setTimeout(() => {
doc.classList.remove('resizing')
callback()
}, delay)
}
Stack trace:
Module build failed (from ./node_modules/babel-loader/lib/index.js):
TypeError: /resources/js/events/resize.js: Cannot read property 'add' of undefined
at ScopeTracker.addReference (/node_modules/babel-plugin-minify-mangle-names/lib/scope-tracker.js:47:34)
at ReferencedIdentifier (/node_modules/babel-plugin-minify-mangle-names/lib/index.js:196:26)
at newFn (/node_modules/@babel/traverse/lib/visitors.js:216:17)
at bfsTraverse (/node_modules/babel-plugin-minify-mangle-names/lib/bfs-traverse.js:32:43)
at Mangler.collect (/node_modules/babel-plugin-minify-mangle-names/lib/index.js:229:7)
at Mangler.run (/node_modules/babel-plugin-minify-mangle-names/lib/index.js:54:12)
at PluginPass.exit (/node_modules/babel-plugin-minify-mangle-names/lib/index.js:526:19)
at newFn (/node_modules/@babel/traverse/lib/visitors.js:175:21)
at NodePath._call (/node_modules/@babel/traverse/lib/path/context.js:55:20)
at NodePath.call (/node_modules/@babel/traverse/lib/path/context.js:42:17)
at NodePath.visit (/node_modules/@babel/traverse/lib/path/context.js:101:8)
at TraversalContext.visitQueue (/node_modules/@babel/traverse/lib/context.js:112:16)
at TraversalContext.visitSingle (/node_modules/@babel/traverse/lib/context.js:84:19)
at TraversalContext.visit (/node_modules/@babel/traverse/lib/context.js:140:19)
at Function.traverse.node (/node_modules/@babel/traverse/lib/index.js:82:17)
at traverse (/node_modules/@babel/traverse/lib/index.js:64:12)
at transformFile (/node_modules/@babel/core/lib/transformation/index.js:107:29)
at transformFile.next (<anonymous>)
at run (/node_modules/@babel/core/lib/transformation/index.js:35:12)
at run.next (<anonymous>)
at Function.transform (/node_modules/@babel/core/lib/transform.js:27:41)
at transform.next (<anonymous>)
at step (/node_modules/gensync/index.js:254:32)
at /node_modules/gensync/index.js:266:13
at async.call.result.err.err (/node_modules/gensync/index.js:216:11)
@ ./resources/js/events/index.js 1:89-126 1:217-231
@ ./resources/js/app.js
This compiles properly:
import { doc } from '../utils/Document';
let resizeTimer = null
export default function debounceResize(callback, delay = 100) {
clearTimeout(resizeTimer)
doc.classList.add('resizing')
resizeTimer = setTimeout(() => {
doc.classList.remove('resizing')
callback()
}, delay)
}
Most helpful comment
The issue seems to be with default functional parameters set to a constant.