React Native 错误:分辨率不明确

Att*_*ila 5 xcode node-modules react-native

当我尝试在 iOS 模拟器上运行 React Native 应用程序时,出现红屏并显示以下错误:

不明确的解决方案:模块“/Users/my-user/Documents/my-RN-app/app/index.js”尝试要求“react-native-vector-icons”,但有几个文件提供此模块。您可以删除或修复它们:

/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__ /文件/package.json

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

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

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

所以最后,我尝试了这个:

  1. sudo rm -rf node_modules(如果我不使用,我会收到“权限被拒绝”,sudo尽管看起来我对该项目中的所有文件/文件夹具有完全的读/写权限)
  2. sudo rm -rf ios/build
  3. npm install
  4. cd ios && pod install
  5. 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"
  }
}
Run Code Online (Sandbox Code Playgroud)

Chr*_*ist 1

我必须手动将 React pod 链接到node_modules

pod 'React', :path => '../node_modules/react-native'

然后清理并再次构建