我正在尝试使用 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";
)。
如果有人可以帮助我解决这个问题,我将不胜感激。谢谢。