expo: Unable to connect to Expo In App purchases for android default.connectAsync not defined.

🐛 Bug Report

Unable to connect to InAppPurchases following the documentation.

Environment

Expo CLI 3.17.21 environment info: System: OS: macOS 10.15.2 Shell: 3.2.57 - /bin/bash Binaries: Node: 12.13.0 - /usr/local/bin/node Yarn: 1.19.1 - /usr/local/bin/yarn npm: 6.12.0 - /usr/local/bin/npm IDEs: Android Studio: 3.5 AI-191.8026.42.35.5900203 Xcode: 11.2.1/11B500 - /usr/bin/xcodebuild npmPackages: expo: ^36.0.2 => 36.0.2 react: ~16.9.0 => 16.9.0 react-native: https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz => 0.61.4 react-navigation: ^4.3.7 => 4.3.7 npmGlobalPackages: expo-cli: 3.17.21

Android

Steps to Reproduce

I performed

npm install expo-in-app-purchases
npm install react-native-unimodules

In my LoadingScreen.js

import * as InAppPurchases from 'expo-in-app-purchases';

componentDidMount() {		
     this.getDetails()
}

getDetails = async () => {
			const history = await InAppPurchases.connectAsync();
}

Actual Behavior

I am getting undefined is not an object (evaluating ‘_ExpoInAppPurchases.default.connectAsync’) if I use

await InAppPurchases.connectAsync();

however if i simply do

await connectAsync();

I get

Can’t find variable: connectAsync

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 25 (3 by maintainers)

Most upvoted comments

@fulljsdev259 Yes, you have to eject expo to bare workflow. Only then it will work unfortunately.

@dorapax-lab no shit. in a month, please tell me again it’s only available in bare workflow.

Has there been any movement on this? I am completely unable to connect to the store. The below is what I ran and what showed up in my terminal after hitting the button on my physical device.

//@ts-check
import { StatusBar } from 'expo-status-bar';
import React, { useState, useEffect } from 'react';
import { Button, StyleSheet, Text, View } from 'react-native';
import { connectAsync } from 'expo-in-app-purchases'

export default function App() {

  useEffect(() => {
    console.log("Test App Started")
  }, [])

  const [name, setName] = useState("Me")
  // const [items, setItems] = useState([])

  const connectButtonAction = async (evnt) => {
    console.log("Connecting to The Store")
    await connectAsync()
  }

  return (
    <View style={styles.container}>
      <Text>Author: {name}</Text>
      <Text>Test App!</Text>
      <StatusBar style="auto" />
      <Button
        onPress={connectButtonAction}
        title="Connect to Store"
        color="#841584"
        accessibilityLabel="Connect to the store"
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#ffeec0',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Results in:

Test App Started
Connecting to The Store

[Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_ExpoInAppPurchases.default.connectAsync')]
at http://192.168.1.17:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:138285:73 in connectAsync$
at http://192.168.1.17:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:138272:37 in connectAsync
at node_modules/react-native/Libraries/Pressability/Pressability.js:691:17 in _performTransitionSideEffects
at node_modules/react-native/Libraries/Pressability/Pressability.js:628:6 in _receiveSignal
at node_modules/react-native/Libraries/Pressability/Pressability.js:524:8 in responderEventHandlers.onResponderRelease
at [native code]:null in forEach
at [native code]:null in callFunctionReturnFlushedQueue

Any and all help would be greatly appreciated.

This is expo sdk’s current limitation and for now only solution is bare work 😕 .

There’s a feature request for managed workflow and it’s marked as Planned: https://expo.canny.io/feature-requests/p/in-app-purchases

@gwalshington FYI With EAS CLI you can build and submit native project in just a few commands. to learn more: https://www.youtube.com/watch?v=7E6zsRpfT4U docs: http://docs.expo.io/eas

Let’s hope this will be prioritised and implemented soon. Also don’t forget to give a thumbs up for above feature request.

@dorapax-lab It’s already ejected, which is why react-native-iap works. Worked out of the box - could not get expo-in-app-purchases to work. I stand by my previous comment that connecting was returning undefined with expo’s iap. I’ve decided not to use that package for this reason, but from what I can tell there are many others experiencing this issue.

@captivatingLunatic, change BillingClint version here. If you are going to use react-native-iap, I using version 7.0.2 and it works very well! Cheers!

I tried both plugins expo-in-app-purchases and react-native-iap. On rn-iap it returns Possible Unhandled Promise Rejection (id: 3): Error: E_IAP_NOT_AVAILABL and at the expo it return [Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_ExpoInAppPurchases.default.connectAsync')]. I’m using ejected expo or bare workflow, the same setup.

Hi @zelin! It looks like something is going on with the module transpiler. What’s happening here is that it’s trying to import the default exported value from expo-in-app-purchases, instead of all methods. Unfortunately, without a small repro I’m not sure what’s going on here. But there are some things that you could try:

// This normally should work
import * as InAppPurchases from 'expo-in-app-purchases';

// You can try importing the method only, see if it works
import { connectAsync } from 'expo-in-app-purchases';

// Or even the old-school `require`
const InAppPurchases = require('expo-in-app-purchases');

Hope it helps!

@byCedric I have tried these and none of that worked for me 😦

Is there any workaround for this without ejecting expo to bare workflow ?