Skip to content

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

Closed

Description

@adamreisnz

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",

Activity

  1. 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[/+] on Feb 7, 2018
  2. sriksm19 commented on Feb 14, 2018

    @sriksm19

    any update on this?

  3. StK88 commented on Feb 16, 2018

    @StK88

    Looks like it's related to #556

  4. adamreisnz commented on Feb 16, 2018

    @adamreisnz
    Author

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

  5. cilliemalan commented on Feb 23, 2018

    @cilliemalan

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

  6. boopathi commented on Feb 28, 2018

    @boopathi
    Member

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

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions