zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.78k stars 749 forks source link

Linking issues with simple Podfile #691

Open curt-tophatter opened 3 years ago

curt-tophatter commented 3 years ago

:beetle: Description

I just wanted to note this mostly for posterity, in case anyone else has this issue going forward.

Running the following throws a Cannot read property 'match' of undefined error for projects that do not require a "more complex" Podfile (example).

yarn react-native link react-native-sound

:beetle: What is the observed behavior?

yarn react-native link react-native-sound --verbose

produces:

error Cannot read property 'match' of undefined
debug TypeError: Cannot read property 'match' of undefined
    at findLineToAddPod (/Users/curthoward/Work/tophatter-react-native/node_modules/@react-native-community/cli/build/commands/link/pods/findLineToAddPod.js:27:44)
    at getLinesToAddEntry (/Users/curthoward/Work/tophatter-react-native/node_modules/@react-native-community/cli/build/commands/link/pods/registerNativeModule.js:32:40)
    at registerNativeModulePods (/Users/curthoward/Work/tophatter-react-native/node_modules/@react-native-community/cli/build/commands/link/pods/registerNativeModule.js:45:27)
    at Object.registerNativeModule [as register] (/Users/curthoward/Work/tophatter-react-native/node_modules/@react-native-community/cli/build/commands/link/ios/common/registerNativeModule.js:24:40)
    at /Users/curthoward/Work/tophatter-react-native/node_modules/@react-native-community/cli/build/commands/link/linkDependency.js:39:16
    at Array.forEach (<anonymous>)
    at linkDependency (/Users/curthoward/Work/tophatter-react-native/node_modules/@react-native-community/cli/build/commands/link/linkDependency.js:18:32)

:beetle: What is the expected behavior?

Regardless of the complexity of the Podfile, the pod should still be added.

:bulb: Possible solution

This issue is actually coming from react-native-community/cli/build/commands/link/pods/findLineToAddPod.js:27. The RegEx used tries to match a target block that isn't necessary, according to the CocoaPods documentation (linked above).

:bulb: Is there a workaround?

I got around this by wrapping the contents of my Podfile in a target block.

Instead of:

target 'MyProject'
# ... flat contents of podfile ...

I did:

target 'MyProject' do
  # ... nested contents of podfile ...
end

:bulb: If the bug is confirmed, would you be willing to create a pull request?

Sure, but it seems like the issue originates externally and should probably be addressed in react-native-community/cli. If you disagree, I'd be happy to handle this case locally in this project.

Which versions are you using?