Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'add' of undefined #792

Closed
adamreisnz opened this issue Feb 7, 2018 · 5 comments
Closed

TypeError: Cannot read property 'add' of undefined #792

adamreisnz opened this issue Feb 7, 2018 · 5 comments

Comments

@adamreisnz
Copy link

Input Code

/**
 * Dependencies
 */
import $ from 'jquery';
import $doc from '../../shared/$doc.js';

/**
 * User panel service
 */
class UserPanelService {

  /**
   * Constructor
   */
  constructor() {

    //ID
    this.id = 'UserPanel';

    //Classes
    this.cToggle = 'UserPanelToggle';
  }

  /**************************************************************************
   * Initialisation
   ***/

  /**
   * Initialisation
   */
  init() {
    this.findElements();
    this.bindToggleHandlers();
    this.bindGlobalCloseHandler();
  }

  /**
   * Find elements
   */
  findElements() {
    this.$userPanel = $(`#${this.id}`);
  }

  /**
   * Bind toggle handlers
   */
  bindToggleHandlers() {
    $doc
      .on('click', `.${this.cToggle}`, () => {
        this.toggle();
      });
  }

  /**
   * Bind global close handler
   */
  bindGlobalCloseHandler() {
    $doc
      .on('click', event => {

        //Not visible?
        if (!this.isVisible()) {
          return;
        }

        //Get target
        const $target = $(event.target);
        const $parents = $target.parents(`.${this.cToggle}`);

        //Clicked on user panel
        if (this.$userPanel[0].contains($target[0])) {
          return;
        }

        //Clicked on toggle
        if ($target.hasClass(this.cToggle) || $parents.length > 0) {
          return;
        }

        //Hide
        this.hide();
      });
  }

  /**************************************************************************
   * Panel visibility
   ***/

  /**
   * Check if visible
   */
  isVisible() {
    return this.$userPanel.is(':visible');
  }

  /**
   * Toggle the user panel
   */
  toggle() {
    this.$userPanel.toggle();
  }

  /**
   * Hide the user panel
   */
  hide() {
    this.$userPanel.hide();
  }

  /**
   * Show the user panel
   */
  show() {
    this.$userPanel.show();
  }
}

/**
 * Export service singleton
 */
export default new UserPanelService();

Forgive me, it's using jQuery, I had to for this project 😩

Actual Output

TypeError: app/components/app/header/user-panel.service.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:191: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:270: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:590: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)
error An unexpected error occurred: "Command failed.\nExit code: 1\nCommand: sh\nArguments: -c babel app --out-file dist/app.min.js --ignore spec.js".

Expected Output

Compiled JS

Details

My .babelrc

{
  "presets": [
    ["env", {
      "targets": {
        "browsers": ["last 2 versions"]
      }
    }],
    "minify"
  ],
  "env": {
    "production": {
      "presets": ["minify"]
    }
  },
  "plugins": [
    ["module-resolver", {
      "alias": {
        "app": "./app/components"
      }
    }]
  ]
}

Versions:

"babel-cli": "^6.26.0",
    "babel-core": "^6.26.0",
    "babel-plugin-module-resolver": "^3.0.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-minify": "^0.3.0",
@adamreisnz adamreisnz changed the title TypeError: app/components/app/header/user-panel.service.js: Cannot read property 'add' of undefined TypeError: Cannot read property 'add' of undefined Feb 7, 2018
@sriksm19
Copy link

any update on this?

@StK88
Copy link

StK88 commented Feb 16, 2018

Looks like it's related to #556

@adamreisnz
Copy link
Author

Yeah looks like it might be actually, I wonder why it has been closed though as it's clearly still an issue.

@cilliemalan
Copy link

babel-minify-webpack-plugin worked for me (and it uses babel-preset-minify)

@boopathi
Copy link
Member

Duplicate of #556. This was fixed with babel-7 and now master is using babel-7.

To get latest canary release - https:/babel/minify/tree/master/docs#canary-version

If you still face this error in the latest master, please comment here to reopen the issue.

devongovett added a commit to devongovett/minify that referenced this issue May 20, 2018
Fixes "Cannot read property 'add' of undefined" error. babel#792 babel#556
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants