【问题标题】:React Native Installing PackagesReact Native 安装包
【发布时间】:2019-03-30 08:23:18
【问题描述】:

React-Native 新手在这里遇到问题,想知道我是否错过了安装软件包的基本步骤。

我一直在尝试使用 react-native-rsa-native 包 (https://github.com/amitaymolko/react-native-rsa-native)

但是我得到了

TypeError: undefined is not an object (evaluating '_reactNativeRsaNative.RSA.generateKeys')

我的测试代码是:

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

import { RSA, RSAKeychain } from 'react-native-rsa-native';

export default class App extends React.Component {

  componentWillMount() {
    RSA.generateKeys(4096) // set key size
      .then(keys => {
        console.log('4096 private:', keys.private) // the private key
        console.log('4096 public:', keys.public) // the public key
      });
  }

  render() {
    ...
  }
}

随后的步骤是:

expo init rsatest --template blank@sdk-31 --yarn
cd rsatest
yarn add react-native-rsa-native
react-native link react-native-rsa-native
yarn start

react-native-rsa-native 包确实出现在 node_modules 目录中,但是我觉得我缺少一些东西。

有什么想法吗?

【问题讨论】:

    标签: react-native package


    【解决方案1】:

    可能相关的一件事是 componentWillMount 已被弃用。

    https://reactjs.org/docs/react-component.html React 文档是 React Native 文档的基础。

    还有componentWillMount(),如果有fetch调用,带有promise,在组件挂载前promise不会返回,组件至少会返回一次empty。

    我建议尝试 componentDidMount()

    希望对你有帮助

    编辑拼写*

    【讨论】:

    • 我已将 componentWillMount 更改为 componentDidMount,但不幸的是仍然存在相同的错误:(
    【解决方案2】:

    该库与 Expo 不兼容。在这里查看原因:react native link using expo?

    所以你可能想expo eject。我认为这也不是一个选择。

    不如试试下面这个? https://github.com/z-hao-wang/react-native-rsa

    【讨论】:

    • 这就解释了为什么它没有并且不会起作用。我看过 react-native-rsa 但选择了 react-native-rsa-native 因为它提供了我最终需要的签名和验证功能。我会继续寻找。非常感谢您的回答。
    【解决方案3】:

    您可以删除节点模块,然后 npm 安装 反应原生链接 react-native run-android/run-ios

    也许

    这很有帮助: how to delete installed library form react native project

    【讨论】:

      猜你喜欢
      • 2018-09-08
      • 1970-01-01
      • 2018-06-10
      • 2022-12-22
      • 2019-11-10
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      • 2019-01-19
      相关资源
      最近更新 更多