babel-relay-plugin具有对“ cypto”的反应本机博览会抛出错误 错误

问题描述

我正在尝试使用babel-plugin-relay包在expo项目中实现react-relay。 它正在Expo Web(npm run web)上运行,但是当我在Android设备(npm start)上运行它时,发生了此错误

错误

The package at "node_modules/babel-plugin-relay/lib/compileGraphQLTag.js" attempted to import the Node standard library module "crypto". It Failed because the native React runtime does not include the Node standard library. Read more at https://docs.expo.io/workflow/using-libraries/#using-third-party-libraries

我的配置

// babel.config.js
module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],plugins: [
      ['relay']
    ]
  };
};
// package.json
  "dependencies": {
    "@absinthe/socket-relay": "^0.2.1","@expo/vector-icons": "^10.2.1","@react-native-community/masked-view": "^0.1.10","@react-navigation/bottom-tabs": "^5.11.1","@react-navigation/native": "^5.8.9","@react-navigation/stack": "^5.12.6","expo": "~39.0.2","expo-asset": "^8.2.0","expo-constants": "^9.2.0","expo-font": "^8.3.0","expo-linking": "^1.0.5","expo-splash-screen": "^0.6.2","expo-status-bar": "~1.0.2","expo-web-browser": "^8.5.0","phoenix": "^1.5.6","react": "16.13.1","react-dom": "16.13.1","react-native": "https://github.com/expo/react-native/archive/sdk-39.0.4.tar.gz","react-native-gesture-handler": "^1.8.0","react-native-paper": "^4.3.1","react-native-safe-area-context": "^3.1.9","react-native-screens": "^2.14.0","react-native-web": "^0.13.18","react-relay": "^10.0.1","relay-runtime": "^10.0.1"
  },"devDependencies": {
    "@babel/core": "~7.9.0","babel-plugin-relay": "^10.0.1","graphql": "^15.4.0","relay-compiler": "^10.0.1"
  },
// relay.config.js
module.exports = {
  src: './src',schema: './schema.graphql',exclude: [
    '**/node_modules/**','**/__mocks__/**','src/__generated__/**'
  ],};

我正在使用babel-plugin-relay / macro来组成graphql片段(import graphql from "babel-plugin-relay/macro";)。

如果有人可以帮助我解决这个问题,我将不胜感激。谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)