motiz88 / react-native-midi

[WIP] Web MIDI implementation for React Native using Expo Modules
MIT License
69 stars 1 forks source link

Unable to install into iOS project #4

Closed dsabsay closed 1 year ago

dsabsay commented 1 year ago

I did this:

npm install @motiz88/react-native-midi
npx pod-install
# Rebuilt project in Xcode
# Reloaded Metro (JS dev server for RN)
# Add code to use requestMIDIAccess

I'm getting Cannot find native module 'ReactNativeMidi. I don't see any related Pod installed (looking at Podfile.lock and browsing Pods in Xcode).

I'm on an M2 MacBook Pro. Xcode 14.2. react-native 0.70.6.

The rest of my app works as expected (using various native modules).

I don't know if this matters, but my terminal session is running in Rosetta, judging by the output of uname -m. I believe all/most binaries I'm running are only x86_64, because they were restored from a previous laptop.

Any pointers or debugging advice would be appreciated. Thanks!

kimchouard commented 1 year ago

If you've installed it with the Readme instruction, make sure to import it into your app using the @, like : import { MIDIMessageEvent, requestMIDIAccess } from "@motiz88/react-native-midi";

Let me know if that worked.

dsabsay commented 1 year ago

@kimchouard Thanks for the reply. My code has the @ already.

kimchouard commented 1 year ago

Okay, can you share the bits of code in which you're importing/using the lib (react-native-midi)?

dsabsay commented 1 year ago

Sure.

import { requestMIDIAccess } from '@motiz88/react-native-midi';
...
  useEffect(() => {
    requestMIDIAccess()
      .then((midiAccess) => {
        console.log(midiAccess.input)
      })
      .catch((e) => alert(`Unable to get MIDI access: ${JSON.stringify(e)}`));
  }, [])
...

I suspect it's something build-related.

motiz88 commented 1 year ago

Hey @dsabsay - I'd be happy to take a look at a repo showing this problem, if you can share one. (Seperately, I'll also try installing the module in a new vanilla RN project, and see if it repros the issue.)

dsabsay commented 1 year ago

Thanks for taking a look. I solved this by configuring my project to use Expo modules (documented here). In short, npx install-expo-modules@latest.

I briefly tried without the Expo stuff. But it seems the Swift code depends on expo-modules-core. And even then, I needed to use a pod :path ../node_modules/... in the Podfile which seemed less than ideal.

I think the README here should encourage people to use the Expo approach unless you know it works otherwise. I didn't try to reproduce, but my one experience suggests users will have a tough time getting it to work without Expo.