问题描述
我正在尝试使用 stripe-react-native(使用 expo 和使用 android)库,但我立即使用了 StripeProvider 我得到了这个错误(我遵循了文档):
TypeError: null is not an object (evaluating '_NativeStripeSdk["default"].initialise')
This error is located at:
in StripeProvider (at App.js:35)
in EnsureSingleNavigator (at BaseNavigationContainer.tsx:409)
in ForwardRef(BaseNavigationContainer) (at NavigationContainer.tsx:91)
in ThemeProvider (at NavigationContainer.tsx:90)
...
这是我使用它的地方:
...
import { StripeProvider } from '@stripe/stripe-react-native'
//pass the ref to your navigation container
import { PersistGate } from 'redux-persist/integration/react'
import { store,persistor } from './store'
import { Provider } from 'react-redux'
import { AppTab } from './Navigation'
export default function App() {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<NavigationContainer>
<StripeProvider
publishableKey="pk_live_L4zEu37Als6Z..."
>
<AppTab />
</StripeProvider>
</NavigationContainer>
</PersistGate>
</Provider>
)
}
我的 package.json:
...
"expo": "~41.0.1","expo-status-bar": "~1.0.4","react": "16.13.1","react-dom": "16.13.1","react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz","react-native-web": "~0.13.12",...
"@stripe/stripe-react-native": "^0.1.2",....
我在这个问题上没有找到任何东西,有人可以帮我看看我做错了什么吗?谢谢!
解决方法
您需要更新您的 Expo 客户端,最近才添加了对 stripe-react-native 的支持:https://github.com/stripe/stripe-react-native/issues/3#issuecomment-846225534
,由于我没有足够的声誉来发表评论,所以我必须将此作为答案发布。扩展 Paul's 解决方案,查看 Expo SDK 41 发布博文的“升级您的应用”部分也很有帮助:https://blog.expo.io/expo-sdk-41-12cc5232f2ef#e10c。
要记住的一些关键事项是,您还需要升级您正在使用的设备上的 Expo 应用程序。如果它们是实体的,则使用它们各自的应用程序商店,如果不是,则您可以删除这些应用程序并重新创建它们,或者运行 <item>
<name>a</name>
<cat>d</cat>
</item>
<item>
<name>a</name>
<cat>z</cat>
</item>
<item>
<name>a</name>
</item>
和 expo client:install:ios
。帮助我的最后一项是在升级后干净利落地运行:expo client:install:android
。