diff --git a/lib/compat/dispatcher-weakref.js b/lib/compat/dispatcher-weakref.js index db97e0f6e1e..8cb99e21501 100644 --- a/lib/compat/dispatcher-weakref.js +++ b/lib/compat/dispatcher-weakref.js @@ -22,11 +22,13 @@ class CompatFinalizer { } register (dispatcher, key) { - dispatcher.on('disconnect', () => { - if (dispatcher[kConnected] === 0 && dispatcher[kSize] === 0) { - this.finalizer(key) - } - }) + if (dispatcher.on) { + dispatcher.on('disconnect', () => { + if (dispatcher[kConnected] === 0 && dispatcher[kSize] === 0) { + this.finalizer(key) + } + }) + } } }