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

Problems requiring EventEmitter2 in browser #43

Closed
topa opened this issue Dec 2, 2012 · 2 comments
Closed

Problems requiring EventEmitter2 in browser #43

topa opened this issue Dec 2, 2012 · 2 comments

Comments

@topa
Copy link

topa commented Dec 2, 2012

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?

@sokra
Copy link
Member

sokra commented Dec 2, 2012

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.

@sokra
Copy link
Member

sokra commented Jan 23, 2013

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants