djipco / webmidi

Tame the Web MIDI API. Send and receive MIDI messages with ease. Control instruments with user-friendly functions (playNote, sendPitchBend, etc.). React to MIDI input with simple event listeners (noteon, pitchbend, controlchange, etc.).
Apache License 2.0
1.53k stars 115 forks source link

ReferenceError: performance is not defined #225

Closed KlutzyBubbles closed 2 years ago

KlutzyBubbles commented 2 years ago

Describe the bug and how to reproduce it From v3.0.3 onwards (I tried it on all versions since), running the following code on NodeJS 14 produces the error.

I have tried on node v16 and the error doesnt appear on later versions.

const { WebMidi } = require('webmidi');

WebMidi.enable({
  callback: midiInit,
  sysex: true
})

function midiInit(e) {
  if (e) {
    console.log(e);
    return;
  }
  let listener = (event) => {
    console.log('EVENT');
    console.log(event);
  }
  WebMidi.addListener("connected", listener);
  WebMidi.addListener("disconnected", listener);
}

This was on windows

Wondering if this would be an easy fix, I tried looking at the commits but there are no release tags for v3.0.2 or v3.0.3. Or if i will just have to compromise and keep at v3.0.2 or migrate my project to v16.

djipco commented 2 years ago

I'm pretty confident we can fix this. I will have to setup an environment with Node.js v14 to test it though. The performance module appeared in Node.js v8.5. I'm not sure what might have changed between v14 and v16.

djipco commented 2 years ago

The performance module appeared in v8.5.0. However, it seems that until v16 you needed to explicitly import it. In v16+ it is automatically imported. Knowing that, I adjusted the library to import it if necessary. Version 3.0.12 (available now) should therefore fix the issue.

Thanks for reporting it.