You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Expo集成Stripe支付时遇TypeError错误求助

解决React Native Expo中接入Stripe支付时的_TypeError: null is not an object_错误

错误详情

TypeError: null is not an object (evaluating '_NativeStripeSdk.default.initialise')

错误截图

在使用@stripe/stripe-react-native包为React Native Expo项目接入Stripe支付时,配置Stripe Provider并传入发布密钥后触发上述错误。

解决步骤

  • 安装适配Expo的Stripe包版本
    不要直接用npm/yarn安装,使用Expo官方安装命令确保版本兼容:

    expo install @stripe/stripe-react-native
    
  • 完成Expo预构建(针对自定义开发构建)
    如果使用的是自定义开发构建(而非Expo Go),必须运行预构建命令配置原生依赖:

    npx expo prebuild --clean
    

    该命令会自动配置iOS/Android端的Stripe原生SDK,避免_NativeStripeSdk为null的问题。

  • 验证Stripe Provider配置正确性
    确保在根组件正确包裹StripeProvider,且传入有效的发布密钥:

    import { StripeProvider } from '@stripe/stripe-react-native';
    
    export default function App() {
      return (
        <StripeProvider
          publishableKey="pk_test_你的有效发布密钥"
          merchantIdentifier="merchant.com.你的应用唯一标识" // iOS必填,Android可选
        >
          {/* 应用子组件 */}
        </StripeProvider>
      );
    }
    

    禁止传入null/undefined的publishableKey,否则会触发同类错误。

  • 清除缓存并重启项目
    执行命令清除Expo缓存,再重启项目:

    npx expo start --clear
    

    同时重启模拟器或真机,确保新依赖生效。

  • 检查Expo SDK版本兼容性
    查看@stripe/stripe-react-native官方文档,确认当前Expo SDK版本与Stripe包版本匹配,比如Expo SDK 50对应Stripe包0.35.0及以上版本。

内容的提问来源于stack exchange,提问作者Anjali Deshmukh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 02:10:57