From 8d36d956cf9a307386090cf17ea76d3693a3b1e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Philippe=20C=C3=B4t=C3=A9?= Date: Thu, 23 Nov 2023 15:04:04 -0500 Subject: [PATCH] Fix jzz import in Node when ESm is used --- src/WebMidi.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/WebMidi.js b/src/WebMidi.js index 313af9999..9ced9d042 100644 --- a/src/WebMidi.js +++ b/src/WebMidi.js @@ -249,10 +249,12 @@ class WebMidi extends EventEmitter { try { window.navigator; } catch (err) { - global.navigator = await Object.getPrototypeOf(async function() {}).constructor(` + let jzz = await Object.getPrototypeOf(async function() {}).constructor(` let jzz = await import("jzz"); return jzz.default; `)(); + if (!global.navigator) global.navigator = {}; // for Node.js prior to v21 + Object.assign(global.navigator, jzz); } // The `performance` module appeared in Node.js v8.5.0 but has started to be automatically