Skip to content

Problems requiring EventEmitter2 in browser #43

Closed

Description

@topa

I want to use EventEmitter2 from hij1nx. While in node context it works in browser context it is undefined.
Probably the last line of the module breaks webpack

;!function(exports, undefined) {

 // ...

}(typeof process !== 'undefined' && typeof process.title !== 'undefined' && typeof exports !== 'undefined' ? exports : window);

Do you have any idea or solution how to solve this problem?

Activity

  1. sokra commented on Dec 2, 2012

    @sokra
    Member

    It does work for me.

    My testcase (test.js):

    var ee = require("./lib/eventemitter2");
    document.write(ee.toString());
    var test = new ee();
    document.write("<br>");
    document.write(JSON.stringify(test));
    webpack-dev-server test.js
    

    http://localhost:8080

    function EventEmitter(conf) { this._events = {}; this.newListener = false; configure.call(this, conf); }
    {"_events":{},"newListener":false}
    

    It is exported by the AMD part of the module:

    // ...
      if (typeof define === 'function' && define.amd) {
        define(function() {
          return EventEmitter;
        });
      } else {
        exports.EventEmitter2 = EventEmitter; 
      }
    // ...

    This means it exports {EventEmitter2: function() {/*...*/}} in node.js through the CommonJs part and function() {/*...*/} in the AMD part. This is a bit weird in the library.

    You can import it with var ee2Lib = require("eventemitter2"), EventEmitter2 = ee2Lib.EventEmitter2 || ee2Lib; to support both types of exports.

  2. sokra commented on Jan 23, 2013

    @sokra
    Member

    I close this issue, please reopen if you still have an 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

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions