【问题标题】:Including paypal-rest-sdk in react-native project produces an error在 react-native 项目中包含 paypal-rest-sdk 会产生错误
【发布时间】:2018-11-02 15:25:11
【问题描述】:

当我导入 Paypal-Rest-SDK 并尝试运行时:

react-native run-android

发生错误:

"undefined is not a function(evaluating 'r(d[9]).configure')"

在发生此错误之前,我删除了node_modules 文件夹并再次重新安装了所有模块,因为我在“评估 process.versions.openssl”时遇到了类似的错误。当我调用node -p process.versions 时,会打印以下内容:

{ http_parser: '2.8.0',
  node: '8.12.0',
  v8: '6.2.414.66',
  uv: '1.19.2',
  zlib: '1.2.11',
  ares: '1.10.1-DEV',
  modules: '57',
  nghttp2: '1.32.0',
  napi: '3',
  openssl: '1.0.2p',
  icu: '60.1',
  unicode: '10.0',
  cldr: '32.0',
  tz: '2017c' }

我的代码如下使用 paypal-sdk:

'use strict';
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, TouchableHighlight, Linking}           from 'react-native';

var paypal = require('paypal-rest-sdk');

paypal.configure({
  mode: 'sandbox', // Sandbox or live
  client_id: 'x',
  client_secret: 'y'});

export default class Paypal extends Component{
        constructor(props)
       {
            super(props);
            console.log(process);
       }
        render()
        {
            return(
                    <View>
                        <Text>This is gonna be a PayPal Thing</Text>
                    </View>
                   );
        }
 }

我希望有人可以帮助我。我几乎整天都在谷歌上搜索这个问题。

更新: 问题不是 paypal-rest-sdk 的包含,而是当我尝试配置 paypal 变量时的下一行。当我将它们注释掉时,错误消失了......但据我所知,有必要配置它

更新2号 运行后 npm install --save paypal-rest-sdk 我又来解决问题了

undefined is not an object (evaluating 'process.versions.openssl')

【问题讨论】:

    标签: react-native paypal-rest-sdk


    【解决方案1】:

    您正在使用 paypal-rest-sdk 这是 NodeJS PayPal SDK,我相信它与 React Native 不兼容。我建议尝试一些特定于 React Native 的东西,例如

    https://www.npmjs.com/package/react-native-paypal-wrapper

    https://www.npmjs.com/package/react-native-paypal

    或者使用普通的 PayPal rest API https://developer.paypal.com/docs/api/overview/#api-requests

    【讨论】:

    • 谢谢!我不知道。我将尝试使用普通的 PayPal Rest API,它为我自己的想法留出了更多空间。
    猜你喜欢
    • 2019-08-31
    • 2020-12-30
    • 2020-10-01
    • 2022-06-24
    • 2021-10-03
    • 2017-11-16
    • 1970-01-01
    • 2016-09-14
    • 2019-07-19
    相关资源
    最近更新 更多