当我尝试在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文件)都丢失了.我之前实际上遇到过这个错误,所以我决定在上面提到的第一个目录位置(在ios / build / ..等下面)删除package.json文件并刷新应用程序,它加载得很好.现在,在尝试再次在iOS模拟器中启动我的应用程序后,我又回到了同样的错误,但是我无法删除package.json文件,因为它现在甚至都不存在于任何一个位置.
我试图在我的app / index.js文件中注释掉react-native-vector-icons lib的导入并重新启动sim,但错误仍然出现.
最后,我试过这个:
> sudo rm -rf node_modules(如果我不使用sudo,我得到“权限被拒绝”,虽然看起来我对这个项目中的所有文件/文件夹都有完全的读/写权限)
> sudo rm -rf ios / build
> npm安装
> cd ios&& pod安装
> react-native链接
然后回到Xcdoe:产品>清洁,然后再次运行模拟器.还是一样的错误.
根据要求,这是我的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’
然后清理并再次构建