它失败了,因为本机React运行时不包含Node标准库

问题描述

位于node_modules\crypto-js\core.js的程序包试图导入Node标准库模块crypto。它失败了,因为本机React运行时不包含Node标准库。在https://docs.expo.io/workflow/using-libraries/#using-third-party-libraries

中了解更多信息

运行npm start

时遇到此错误

解决方法

对于博览会而不是加密,您可以使用 expo-crypto 您可以按如下方式安装它 expo install expo-crypto

在你的代码中

import React,{ useEffect } from 'react';
import { StyleSheet,View,Text } from 'react-native';
import * as Crypto from 'expo-crypto';

export default function App() {
  useEffect(() => {
    (async () => {
      const digest = await Crypto.digestStringAsync(
        Crypto.CryptoDigestAlgorithm.SHA256,'Github stars are neat'
      );
      console.log('Digest: ',digest);
      /* Some crypto operation... */
    })();
  },[]);
...

来自 exp 文档