question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'add' of undefined

See original GitHub issue

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' }

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:18
  • Comments:20

github_iconTop GitHub Comments

4reactions
mjakobiscommented, Jan 21, 2020

The issue seems to be with default functional parameters set to a constant.

2reactions
somewhatabstractcommented, Feb 17, 2020

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)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property 'add' of undefined
You want to call add on the tile, but try to access the add function of the tiles array itself. This does not...
Read more >
Error: Cannot read property "add" of undefined · Issue #19
Basically, this.$el or that.$refs['app-navbar-id'] seem to be undefined, so it is trying to add classes to a classList of an undefined element.
Read more >
Uncaught TypeError: Cannot read property of undefined In
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >
Uncaught TypeError: Cannot read property 'add' of undefined
In the Console i get an Error caused by WPForms. The Error states: Uncaught TypeError: Cannot read property 'add' of undefined. The page...
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
The TypeError : Cannot read property of undefined is one of the most common type errors in JavaScript. It occurs when a property...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found