Tonejs/Midi

ReferenceError: fetch is not defined. (Doesn't work on Node.js, only works in browser)

aueangpanit opened this issue · 1 comments

When running this code below:

import { Midi } from '@tonejs/midi'

;(async () => {
  const midi = await Midi.fromUrl('./Yiruma-River-Flows-In-You.mid')
  midi.tracks.forEach(track => {
    const notes = track.notes
    console.log(notes)
  })
})()

I'm getting this error:

ReferenceError: fetch is not defined

fetch is only available in browser environments, when using Midi inside of Node.js, you can use it this way:

const fs = require("fs");

const file = fs.readFileSync("./test2.mid");
const midi = new Midi(file);

#132 (comment)