interceptors icon indicating copy to clipboard operation
interceptors copied to clipboard

The `EventEmitter` property is not defined on the browser side

Open lenqwang opened this issue 2 years ago • 2 comments

image image

When I using this module in the browser, I can't find the 'EventEmitter' property in the console output. I guess this is because the 'strict-event-emitter' module relies on the native 'events' module of Node.js. Is there any way to solve this problem?

lenqwang avatar Jul 26 '22 09:07 lenqwang

Hi @lenqwang ,

you should use evenemitter3 which is browser compatible. you can take the reference from it's github repo https://github.com/primus/eventemitter3. We were also getting the same error with events, which is not compatible with Browser i guess so.

hiteshkalwani avatar Sep 02 '22 06:09 hiteshkalwani

I think StrictEventEmitter cannot run in the browser because it extends EventEmitter, which is not a thing in the browser.

We should write a different module for it that'd be imported in the browser, and use EventTarget as the base class instead. The issue here is that EventTarget and EventEmitter are not compatible, as emitter has more properties and is, generally, a totally different thing.

Strange that I've never encountered this while working with Interceptors + MSW in the browser. How are you getting this error?

kettanaito avatar Oct 13 '22 14:10 kettanaito

I'm moving forward with this by ditching EventEmitter and utilizing EventTarget + type-safety in https://github.com/open-draft/strict-event-emitter/pull/8. Afaik, we should be fine with the interface EventTarget provides. Will see.

kettanaito avatar Dec 20 '22 18:12 kettanaito

I'm moving forward with this by ditching EventEmitter and utilizing EventTarget + type-safety in https://github.com/open-draft/strict-event-emitter/pull/8. Afaik, we should be fine with the interface EventTarget provides. Will see.

Thanks @kettanaito

lenqwang avatar Jan 04 '23 04:01 lenqwang

Released: v0.19.5 🎉

This has been released in v0.19.5!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

kettanaito avatar Feb 06 '23 23:02 kettanaito