From 6ca28c2a49694683972edb535c5f0f5887dea9e0 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Tue, 7 Nov 2023 17:01:43 +0100 Subject: [PATCH] fix: correctly import `EventEmitter` to prevent errors with bundlers (#145) Importing EventEmitter like `const EventEmitter = require('events')` creates errors with bundlers like esbuild, vite and so on: `TypeError: EventEmitter2 is not a constructor` --- generate.js | 2 +- parser.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/generate.js b/generate.js index ebb64d7..2abf91d 100644 --- a/generate.js +++ b/generate.js @@ -1,5 +1,5 @@ const writeToStream = require('./writeToStream') -const EventEmitter = require('events') +const { EventEmitter } = require('events') const { Buffer } = require('buffer') function generate (packet, opts) { diff --git a/parser.js b/parser.js index 608c6f8..db78183 100644 --- a/parser.js +++ b/parser.js @@ -1,5 +1,5 @@ const bl = require('bl') -const EventEmitter = require('events') +const { EventEmitter } = require('events') const Packet = require('./packet') const constants = require('./constants') const debug = require('debug')('mqtt-packet:parser')