Cannot read property 'add' of undefined while parsing file
- Dominant language
- JavaScript
- Stars
- 4.4k
- Forks
- 217
- PR merge metrics
- No merged PRs in 30d
Description
Error during minification
> Cannot read property 'add' of undefined while parsing file:
thrown here https://github.com/babel/minify/blob/8f9c7c0a32103653bd6793d0ce44730f937e1ddf/packages/babel-plugin-minify-mangle-names/src/scope-tracker.js#L78
while parsing this file
https://github.com/MetaMask/metamask-extension/blob/239f5f7fa60a05f3b98eb00a9bbb7d27ee48eed1/ui/helpers/utils/conversions.util.js
**Expected Output**
no error
**Stack Trace**
```
/home/xyz/Development/metamask-extension/ui/helpers/utils/conversions.util.js
at ScopeTracker.addReference (/home/xyz/Development/metamask-extension/node_modules/babel-plugin-minify-mangle-names/lib/scope-tracker.js:47:34)
at ReferencedIdentifier (/home/xyz/Development/metamask-extension/node_modules/babel-plugin-minify-mangle-names/lib/index.js:202:26)
at newFn (/home/xyz/Development/metamask-extension/node_modules/@babel/traverse/lib/visitors.js:218:17)
at bfsTraverse (/home/xyz/Development/metamask-extension/node_modules/babel-plugin-minify-mangle-names/lib/bfs-traverse.js:38:43)
at Mangler.collect (/home/xyz/Development/metamask-extension/node_modules/babel-plugin-minify-mangle-names/lib/index.js:235:7)
at Mangler.run (/home/xyz/Development/metamask-extension/node_modules/babel-plugin-minify-mangle-names/lib/index.js:60:12)
at PluginPass.exit (/home/xyz/Development/metamask-extension/node_modules/babel-plugin-minify-mangle-names/lib/index.js:546:19)
at newFn (/home/xyz/Development/metamask-extension/node_modules/@babel/traverse/lib/visitors.js:177:21)
at NodePath._call (/home/xyz/Development/metamask-extension/node_modules/@babel/traverse/lib/path/context.js:53:20)
at NodePath.call (/home/xyz/Development/metamask-extension/node_modules/@babel/traverse/lib/path/context.js:40:17)
```
**Configuration**
```
module.exports = function (api) {
api.cache(false);
return {
parserOpts: {
strictMode: true,
},
presets: [
'@babel/preset-typescript',
[
'@babel/preset-env',
{
targets: {
browsers: ['chrome >= 66', 'firefox >= 68'],
},
},
],
'@babel/preset-react',
'babel-preset-minify',
],
plugins: [
'@babel/plugin-transform-runtime',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator'
],
};
};
```
Contributor guide
Research direction
Start with packages/babel-plugin-minify-mangle-names/src/scope-tracker.js at the reported line and reproduce the failure while parsing ui/helpers/utils/conversions.util.js using the provided Babel configuration. Trace the ReferencedIdentifier and ScopeTracker.addReference calls in the stack trace; done means the file minifies without the reported undefined-property error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100