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

unable to use EventEmitter with "require", empty object instead of a class #1284

Closed
Tracked by #1523
nya1 opened this issue Sep 28, 2022 · 0 comments
Closed
Tracked by #1523
Labels
bug Something isn't working needs repro Needs an example to reproduce

Comments

@nya1
Copy link

nya1 commented Sep 28, 2022

Version

0.1.13

Platform

Linux debian 5.10.0-11-amd64 #1 SMP Debian 5.10.92-2 (2022-02-28) x86_64 GNU/Linux

What steps will reproduce the bug?

// file test.js
const EventEmitter = require('events');

console.log('typeof', typeof EventEmitter)
console.log('content of event emitter', EventEmitter)
console.log('prototype of event emitter', EventEmitter.prototype)

by executing the file in bun with bun ./test.js, the output is:

typeof object
content of event emitter {}
prototype of event emitter undefined

instead executing the same script in node (16) I get:

typeof function
content of event emitter function EventEmitter() {
  EventEmitter.init.call(this);
}
prototype of event emitter EventEmitter {
  _events: undefined,
  _eventsCount: 0,
  _maxListeners: undefined,
  setMaxListeners: [Function: setMaxListeners],
  getMaxListeners: [Function: getMaxListeners],
  emit: [Function: emit],
  addListener: [Function: addListener],
  on: [Function: addListener],
  prependListener: [Function: prependListener],
  once: [Function: once],
  prependOnceListener: [Function: prependOnceListener],
  removeListener: [Function: removeListener],
  off: [Function: removeListener],
  removeAllListeners: [Function: removeAllListeners],
  listeners: [Function: listeners],
  rawListeners: [Function: rawListeners],
  listenerCount: [Function: listenerCount],
  eventNames: [Function: eventNames] }

How often does it reproduce? Is there a required condition?

EventEmitter appears to be empty only when it's imported via CommonJS require, instead with ES6 import it works as expected.

What is the expected behavior?

EventEmitter should be a class with all the standard node methods

What do you see instead?

EventEmitter is an empty object

Additional information

It would be nice to make it work via require as many modules are still using the require notation to import EventEmitter.

@nya1 nya1 added bug Something isn't working needs repro Needs an example to reproduce labels Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs repro Needs an example to reproduce
Projects
None yet
Development

No branches or pull requests

1 participant