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.54k stars 116 forks source link

The requested module does not provide an export named 'default' #146

Closed michaelcaterisano closed 3 years ago

michaelcaterisano commented 3 years ago

I'm trying out webmidi 2.5.2 in a typescript environment and am getting an error when importing webmidi like this: import Webmidi from "webmidi";.

The requested module does not provide an export named 'default'

I also tried import * as WebMidi from "webmidi", but then I get the following error:

Uncaught TypeError: Cannot read property 'WebMidi' of undefined
    at webmidi.min.js:31
    at webmidi.min.js:31
djipco commented 3 years ago

Unfortunately, I am not a TypeScript user and know very little about it. For that reason, WebMidi.js does not officially support TypeScript yet. I am looking to change that for version 3 but will need a knowledgeable TypeScript dev to work on the type definitions.

At one point, users have reported that it was working (as you saw in issue #82) . I'm not sure why it isn't working for you.

For personal bandwidth reasons, official TypeScript support will not come before version 3 (unless someone chimes in to help).

michaelcaterisano commented 3 years ago

Thanks @djipco. I did get the following syntax to work, which I found in the Tone.js/ui library:

const WebMidi: import("webmidi").WebMidi = require("webmidi");

A little funky, but it works!

djipco commented 3 years ago

@michaelcaterisano Thank you so much for taking the time to report back. It will probably be helpful to others. I added your technique to the README.

djipco commented 3 years ago

I tentatively added a types directory with d.ts files for all current classes (this is what the TypeScript compiler outputted). Is the usual practice to have a single index.d.ts file? In any case, if you want to give it go, be my guest!

By the way, this is in the develop branch for v3.

edellaq commented 3 years ago

Trying to interface a simple SPA application to my Fishman TriplePlay Controller. Using v.2.5.2 I'm able to read the played notes, I'm having some trouble with sysex management. 1) is the WebMidi.enable(...,true) necessary only once, or should it be issued (without 'true' parameter) again after sending the data initialisation array, when adding the event listeners?

2) Fishman doesn't provide support about sysex messages, and I'm trying to intercept the midi data with a MIDI monitor, but I'm unable to let it work. In particular I have to switch the controller from poly to mono mode (1 channel per guitar string), but it works only after I launch the proprietary sw, so I think I'm doing something wrong... Can someone post a complete example of a sysex communication?

djipco commented 3 years ago

@edellaq Since your question is not related to this thread, would you mind opening a new thread or, better yet, post it on the forum?

edellaq commented 3 years ago

oops, sorry, will do. (I clicked on the link in the email notification, didn't notice the wrong thread)