gpt4 book ai didi

xcode - react native 错误 : Ambiguous resolution

转载 作者:行者123 更新时间:2023-12-01 04:42:09 25 4
gpt4 key购买 nike

当我尝试在 iOS 模拟器上运行我的 React Native 应用程序时,我看到了一个带有以下错误的红色屏幕:

Ambiguous resolution: module '/Users/my-user/Documents/my-RN-app/app/index.js' tries to require 'react-native-vector-icons', but there are several files providing this module. You can delete or fix them:

/Users/my-user/Documents/my-RN-app/ios/build/Build/Products/Debug-iphonesimulator/MyApp.app/my-RN-app/node_modules/react-native/local-cli/core/__fixtures__/files/package.json

/Users/my-user/Documents/my-RN-app/node_modules/react-native/local-cli/core/__fixtures__/files/package.json



但是,上面的两个文件(package.json 文件)都丢失了。我之前确实遇到过这个错误,所以我决定删除上面提到的第一个目录位置中的 package.json 文件(在 ios/build/.. 等下)并刷新应用程序,它加载得很好。现在,在尝试在 iOS 模拟器中再次启动我的应用程序后,我又回到了同样的错误,但我无法删除 package.json 文件,因为它现在在任何一个位置都不存在。

我试图将 react-native-vector-icons 的导入注释掉lib 在我的 app/index.js 文件中并重新启动 sim,但错误仍然出现。

所以最后,我试过这个:
  • sudo rm -rf node_modules (如果我不使用 sudo,我会得到“权限被拒绝”,尽管我似乎对该项目中的所有文件/文件夹具有完全读/写权限)
  • sudo rm -rf ios/build
  • npm install
  • cd ios && pod install
  • react-native link

  • 然后回到 Xcdoe:Product > Clean,然后我再次运行模拟器。还是一样的错误。

    根据要求,这是我的 package.json 文件:
     {
    "name": "myApp",
    "version": "0.0.1",
    "private": true,
    "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "run-ios": "node_modules/.bin/react-native run-ios",
    },
    "dependencies": {
    "art": "^0.10.1",
    "auto-bind": "^1.1.0",
    "axios": "^0.16.1",
    "eslint-plugin-react-native": "^2.3.1",
    "jwt-decode": "^2.2.0",
    "moment": "^2.19.1",
    "native-base": "^2.3.1",
    "prop-types": "^15.5.8",
    "pubnub": "^4.18.0",
    "react": "^16.0.0",
    "react-native": "^0.49.3",
    "react-native-actionsheet": "^2.3.0",
    "react-native-device-info": "^0.11.0",
    "react-native-fabric": "^0.5.1",
    "react-native-fingerprint-scanner": "^2.2.1",
    "react-native-flip-card": "^3.5.2",
    "react-native-google-analytics-bridge": "^5.3.3",
    "react-native-haptic": "^1.0.5",
    "react-native-image-base64": "^0.1.3",
    "react-native-image-picker": "^0.26.7",
    "react-native-image-resizer": "^1.0.0",
    "react-native-keyboard-aware-scroll-view": "^0.4.3",
    "react-native-keyboard-spacer": "^0.4.1",
    "react-native-keychain": "^1.2.1",
    "react-native-maps": "^0.17.1",
    "react-native-modal-dropdown": "^0.5.0",
    "react-native-mplayer": "^1.0.1",
    "react-native-notifications-badge-extensions": "^1.0.5",
    "react-native-permissions": "^0.2.7",
    "react-native-pie": "^0.4.0",
    "react-native-router-flux": "^4.0.0-beta.26",
    "react-native-snap-carousel": "^3.2.3",
    "react-native-tag-input": "0.0.18",
    "react-native-tooltip": "^5.2.0",
    "react-native-uuid-generator": "^3.0.2",
    "react-native-vector-icons": "^4.3.0",
    "react-native-version-number": "^0.1.3",
    "react-native-voice": "^0.2.5",
    "react-navigation": "^1.2.0",
    "sprintf-js": "^1.0.3",
    "validator": "^9.2.0"
    },
    "devDependencies": {
    "babel-jest": "18.0.0",
    "babel-preset-react-native": "^4.0.0",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "enzyme-to-json": "^3.3.1",
    "eslint": "^3.14.1",
    "eslint-config-airbnb": "^14.1.0",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^4.0.0",
    "eslint-plugin-react": "^7.5.1",
    "jest": "18.1.0",
    "jest-serializer-enzyme": "^1.0.0",
    "jsdom": "11.6.2",
    "jsdom-global": "3.0.2",
    "metro-bundler": "^0.20.0",
    "react-addons-test-utils": "^15.6.2",
    "react-dom": "^16.2.0",
    "react-native-mock": "^0.3.1",
    "react-test-renderer": "16.0.0-alpha.12",
    "sinon": "^4.1.2"
    },
    "resolutions": {
    "moment": "2.19.1"
    }
    }

    最佳答案

    我必须手动将 React pod 链接到 node_modules :
    pod 'React', :path => '../node_modules/react-native'
    然后清理并再次构建

    关于xcode - react native 错误 : Ambiguous resolution,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49544015/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com