Axios版本1.5.1无法在nxworkspace和REACT本机新版本(0.72.4)上正常工作

我在nxworskspace中创建了一个Reaction本机应用程序,同时try 在该应用程序中解决axios问题,我在下面的Imageenter image description here中提到了这个错误.如果我将axios版本降级到0.27.2,它可以正常工作,但它不能正常工作在axios版本1.5.1上.出现此问题的任何具体原因,或者我没有配置某些内容.如有任何帮助,我们将不胜感激,提前谢谢.我在下面提到了我的Package.json代码.

  "name": "@sampleapp/source",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {},
  "private": true,
  "dependencies": {
    "@react-native-async-storage/async-storage": "^1.19.2",
    "@react-native-community/netinfo": "^9.4.1",
    "@react-navigation/native": "^6.1.7",
    "@react-navigation/stack": "^6.3.17",
    "axios": "^1.5.1",
    "formik": "^2.4.3",
    "promise": "^8.3.0",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.72.3",
    "react-native-base64": "^0.2.1",
    "react-native-crypto-js": "^1.0.0",
    "react-native-elements": "^3.4.3",
    "react-native-encrypted-storage": "^4.0.3",
    "react-native-popover-view": "^5.1.2",
    "react-native-safe-area-context": "^4.7.1",
    "react-native-screens": "^3.24.0",
    "react-native-toast-message": "^2.1.6",
    "react-native-vector-icons": "^10.0.0",
    "tslib": "^2.3.0",
    "yup": "^1.2.0"
  },
  "devDependencies": {
    "@babel/preset-react": "^7.14.5",
    "@nx/detox": "16.6.0",
    "@nx/eslint-plugin": "16.6.0",
    "@nx/jest": "16.6.0",
    "@nx/js": "16.6.0",
    "@nx/linter": "16.6.0",
    "@nx/react-native": "16.6.0",
    "@nx/workspace": "16.6.0",
    "@react-native-community/cli": "11.3.5",
    "@react-native-community/cli-platform-android": "11.3.5",
    "@react-native-community/cli-platform-ios": "11.3.5",
    "@react-native/metro-config": "^0.72.9",
    "@testing-library/jest-dom": "5.16.5",
    "@testing-library/jest-native": "5.4.2",
    "@testing-library/react-native": "12.1.2",
    "@types/jest": "^29.4.0",
    "@types/node": "18.14.4",
    "@types/react": "18.0.28",
    "@types/react-native": "0.72.2",
    "@typescript-eslint/eslint-plugin": "^5.60.1",
    "@typescript-eslint/parser": "^5.60.1",
    "babel-jest": "^29.4.1",
    "detox": "^20.11.1",
    "eslint": "~8.15.0",
    "eslint-config-prettier": "8.1.0",
    "eslint-plugin-import": "2.27.5",
    "eslint-plugin-jsx-a11y": "6.7.1",
    "eslint-plugin-react": "7.32.2",
    "eslint-plugin-react-hooks": "4.6.0",
    "jest": "^29.4.1",
    "jest-circus": "^29.4.1",
    "jest-environment-jsdom": "^29.4.1",
    "jest-react-native": "18.0.0",
    "metro": "0.76.7",
    "metro-babel-register": "0.76.7",
    "metro-config": "0.76.7",
    "metro-react-native-babel-preset": "0.76.7",
    "metro-react-native-babel-transformer": "0.76.7",
    "metro-resolver": "0.76.7",
    "nx": "16.6.0",
    "nx-cloud": "latest",
    "prettier": "^2.6.2",
    "react-native-svg": "13.9.0",
    "react-native-svg-transformer": "1.0.0",
    "react-test-renderer": "18.2.0",
    "ts-jest": "^29.1.0",
    "ts-node": "10.9.1",
    "typescript": "~5.1.3"
  },
  "nx": {
    "targets": {}
  }
}

推荐答案

try 将此代码添加到metro.config.js中

resolver: {
    unstable_enablePackageExports: true,
    unstable_conditionNames: ['browser', 'require', 'react-native'],
  },

source

React-native相关问答推荐

如何在react native 中将选定的自定义复选框数据发送到下一页?

如何在 React-Native 中创建检测自动位置的map

react-native redux 和 ListView

用hooks钩子react context上下文防止重新渲染

由于依赖关系,在 run-android 上构建失败

Undefined 不是判断 this.state.* 的对象

如何在 React Native cli 中获取 SHA-1 密钥?

如何在 React Native 中获取 TextInput 相对于其父级或屏幕的光标位置

如何在 React Native 中模拟align-items:baseline?

使用像 React Navigation 这样的基于 JS 的导航解决方案优缺点?

如何判断 goBack() 函数在react-navigation 中是否可行?

React-Native: measure测量一个视图

我可以将标题传递给图像源吗?

在 React Native App 中禁用屏幕捕获/ScreenShot

Native Script 与 react native 和 ionic 框架的区别

React Native 得到这个错误'Unrecognized operator abs'

如何在react-native中显示toast消息

如何在react-native中关闭模态

React Navigation 切换背景 colored颜色 和样式 StackNavigator

如何在 react-native 中为带有图标的按钮建模