achorein / expo-share-intent

🚀 Simple share intent in an Expo Native Module
MIT License
128 stars 13 forks source link

TypeError: 0, _expoModulesCore.requireOptionalNativeModule is not a function (it is undefined) #8

Closed 03balogun closed 4 months ago

03balogun commented 4 months ago

Thank you for working on this.

Describe the bug I get this error after following the installation process see attached screenshot.

TypeError: 0, _expoModulesCore.requireOptionalNativeModule is not a function (it is undefined), js engine: hermes

Here's my usage example:

import { useShareIntent } from 'expo-share-intent'

export const useShareIntentHandler = () => {
  const { hasShareIntent, shareIntent, resetShareIntent } = useShareIntent() // When I remove this line, and comment out the code below the error goes away

  useEffect(() => {
    try {
      const sharedFiles = shareIntent.files
      if (hasShareIntent && sharedFiles?.length) {
        const uris = sharedFiles.map(file => file?.path)

        uploadImages(uris).finally(() => {
          resetShareIntent()
        })
      }
    } catch (e) {
      //
    }
  }, [hasShareIntent, resetShareIntent, shareIntent])
}

To Reproduce Steps to reproduce the behavior

Environment give the output of the following command npx react-native info

Additional context Add any other context about the problem here.

anton950712 commented 4 months ago

I have the same issue. Looks like it is happening because the package using expo 50 and in our projects we have expo 49. I didn't found how to solve the problem (Do no want to update expo because it uses new RN architecture and I will need to do full app testing after the change).

03balogun commented 4 months ago

I have the same issue. Looks like it is happening because the package using expo 50 and in our projects we have expo 49. I didn't found how to solve the problem (Do no want to update expo because it uses new RN architecture).

I thought as much, I am looking to update expo for now because I have other dependencies that are yet to support expo 50

03balogun commented 4 months ago

I have the same issue. Looks like it is happening because the package using expo 50 and in our projects we have expo 49. I didn't found how to solve the problem (Do no want to update expo because it uses new RN architecture and I will need to do full app testing after the change).

I am not sure it's because of expo 50 since the package supports from 49> https://github.com/achorein/expo-share-intent/blob/main/package.json#L69

anton950712 commented 4 months ago

I have the same issue. Looks like it is happening because the package using expo 50 and in our projects we have expo 49. I didn't found how to solve the problem (Do no want to update expo because it uses new RN architecture and I will need to do full app testing after the change).

I am not sure it's because of expo 50 since the package supports from 49> https://github.com/achorein/expo-share-intent/blob/main/package.json#L69

Possibly it is related to "@expo/config-plugins" (not expo 50 as is). After installing the package I'm getting the error after running "npx expo-doctor".

Expected package @expo/config-plugins@~7.2.2
Found invalid:
  @expo/config-plugins@7.8.4
  (for more info, run: npm why @expo/config-plugins)
Advice: Upgrade dependencies that are using the invalid package versions0.

I've tried everything from here (https://github.com/expo/expo/issues/26570) but nothing helps.

achorein commented 4 months ago

At the moment the plugin support only expo 50, for expo 49 you can use the old demo here https://github.com/achorein/expo-share-intent-demo

Package json mention 49 because i was using it on my first iteration. Maybe it worth it to do the work for 49 as it's currently supported by expo team.

For expo-doctor dependancies just add a resolutions to your package json.

03balogun commented 4 months ago

Using expo-share-intent-demo works locally but fails during eas build due to peer dependency issues (I was able to force it locally.)

Yes, It will definitely be worth it to support 49.

achorein commented 4 months ago

Alright, will work on a expo 49 version in the next days, i keep you in touch.

achorein commented 4 months ago

here we go, version 0.2.0 just released for expo 49 support ! a corresponding branch is available here for examples.

@03balogun let me know if it works for you

03balogun commented 4 months ago

Thank you so much for working on this, I will test it out and revert.

03balogun commented 4 months ago

here we go, version 0.2.0 just released for expo 49 support ! a corresponding branch is available here for examples.

@03balogun let me know if it works for you

@achorein It works locally but I get the error below during eas build, do you have an idea why that is?

"Based on dependency analysis" in the script phase. (in target 'React-utils' from project 'Pods')

/Users/expo/workingdir/build/ios/APPName.xcodeproj: error: Provisioning profile "*[expo] com.appname.app.share-extension AppStore 2024-02-23T12:49:33.012Z" doesn't support the App Groups capability. (in target 'ShareExtension' from project 'APPName')

/Users/expo/workingdir/build/ios/APPName.xcodeproj: error: Provisioning profile "*[expo] com.appname.app.share-extension AppStore 2024-02-23T12:49:33.012Z" doesn't include the com.apple.security.application-groups entitlement. Profile qualification is using entitlement definitions that may be out of date. Connect to network to update. (in target 'ShareExtension' from project 'APPName')
achorein commented 4 months ago

🤔 did you use an interactive command for expo build ? Expo should ask to update the apple profile of the share extension before sending it to the eas build. Ensure your profiles are up to date.

anton950712 commented 4 months ago

I have tested and it works for Android. But I found a problem that in case the app is NOT opened and I'm doing sharing, then the app just opening WITHOUT shareIntent info (Sharing just URL).

console.log(hasShareIntent, shareIntent, resetShareIntent, error)
null {"files": null, "text": null} [Function resetShareIntent] undefined
achorein commented 4 months ago

@anton950712 thanks for your feedback, can you open a new issue for your sharing workflow problem. I will close this one (related to expo 49 compatibility)

03balogun commented 4 months ago

🤔 did you use an interactive command for expo build ? Expo should ask to update the apple profile of the share extension before sending it to the eas build. Ensure your profiles are up to date.

Yes, I used interactive command, and yes Expo asked to update app profile which it did.

Here's the full error log


warning: Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'ReactCommon' from project 'Pods')

/Users/expo/workingdir/build/ios/AppName.xcodeproj: error: Provisioning profile "*[expo] com.appname.app.OneSignalNotificationServiceExtension AppStore 2023-12-03T18:38:47.715Z" doesn't match the entitlements file's value for the com.apple.security.application-groups entitlement. Profile qualification is using entitlement definitions that may be out of date. Connect to network to update. (in target 'OneSignalNotificationServiceExtension' from project 'AppName')

warning: Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'React-utils' from project 'Pods')

/Users/expo/workingdir/build/ios/AppName.xcodeproj: error: Provisioning profile "*[expo] com.appname.app.share-extension AppStore 2024-03-03T06:17:47.036Z" doesn't support the App Groups capability. (in target 'ShareExtension' from project 'AppName')

/Users/expo/workingdir/build/ios/AppName.xcodeproj: error: Provisioning profile "*[expo] com.appname.app.share-extension AppStore 2024-03-03T06:17:47.036Z" doesn't include the com.apple.security.application-groups entitlement. Profile qualification is using entitlement definitions that may be out of date. Connect to network to update. (in target 'ShareExtension' from project 'AppName')

warning: Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'React-Codegen' from project 'Pods')

warning: Run script build phase '[CP-User] Generate app.config for prebuilt Constants.manifest' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'EXConstants' from project 'Pods')

warning: Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'React-NativeModulesApple' from project 'Pods')

Here's screenshot of the provisioned profile.

leverage
achorein commented 4 months ago

your provisioned profile looks good...

Do you have the correct group in your ios/ShareExtension/ShareExtension.entitlements file ? On expo prebuild output what is your app identifier ? does it match ?

⠧ Running prebuild[expo-share-intent] add ios share extension (scheme:exposhareintentexample appIdentifier:expo.modules.exposhareintent.example)

looks like a wrong build process or missconfiguration. your project works locally on ios simulator and you juste run the build command from here, or do have you a different CI process to push the build.

achorein commented 4 months ago

Please open a new issue if your problem persist with your profile as it's a different problem