【问题标题】:React native: Can't run project in iOS mode - Duplicate module nameReact native:无法在 iOS 模式下运行项目 - 模块名称重复
【发布时间】:2018-01-27 05:34:03
【问题描述】:

我正在尝试在 iOS 模式下运行一个 react native 项目。

$ react-native run-ios

但我在错误中运行

Failed to build DependencyGraph: @providesModule naming collision:
Duplicate module name: react-animated
Paths: /Users/mobile/node_modules/react-native-image-carousel/node_modules/react-native/Libraries/Animated/release/package.json collides with /Users/mobile/node_modules/react-native/Libraries/Animated/release/package.json

This error is caused by a @providesModule declaration with the same name across two different files.
Error: @providesModule naming collision:
Duplicate module name: react-animated
Paths: /Users/mobile/node_modules/react-native-image-carousel/node_modules/react-native/Libraries/Animated/release/package.json collides with /Users/mobile/node_modules/react-native/Libraries/Animated/release/package.json

This error is caused by a @providesModule declaration with the same name across two different files.
at HasteMap._updateHasteMap (/Users/mobile/node_modules/react-native/packager/react-packager/src/node-haste/DependencyGraph/HasteMap.js:158:13)
at /Users/mobile/node_modules/react-native/packager/react-packager/src/node-haste/DependencyGraph/HasteMap.js:133:31

我不明白这个问题,真的需要一些帮助来解决问题。


这就是我设置系统的方式 (macOS Sierra):

$ brew install node
$ brew install watchman
$ sudo npm install -g react-native-cli
$ npm install invariant --save-dev
$ npm install

一切都应该安装好:

版本

$ node -v
  v4.0.0

$ react-native -v
  react-native-cli: 2.0.1
  react-native: 0.40.0

$ watchman -v
  4.7.0

package.json

{
  "dependencies": {
    "react": "~15.4.0-rc.4",
    "react-native": "0.40.0",
    "react-native-image-carousel": "^0.3.2",
    "react-native-image-picker": "^0.25.7",
    "react-native-local-mongodb": "^1.8.2"
  },
  "devDependencies": {
    "babel-jest": "18.0.0",
    "babel-preset-react-native": "1.9.1",
    "invariant": "^2.2.2",
    "jest": "18.1.0",
    "react-test-renderer": "~15.4.0-rc.4"
  },
  "jest": {
    "preset": "react-native"
  }
}

npm 列表

$ npm list --depth=0

├── babel-jest@18.0.0
├── babel-preset-react-native@1.9.1
├── invariant@2.2.2
├── jest@18.1.0
├── react@15.4.2
├── react-native@0.40.0
├── react-native-image-carousel@0.3.2
├── react-native-image-picker@0.25.7
├── react-native-local-mongodb@1.8.2
└── react-test-renderer@15.4.2

【问题讨论】:

    标签: ios node.js react-native npm


    【解决方案1】:

    清除缓存并重新启动项目。

    按照以下步骤清除 React Native 包中的缓存。

    watchman watch-del-all

    rm -rf $TMPDIR/react-*

    rm -rf node_modules/

    npm cache clean

    npm install

    npm start -- --reset-cache

    【讨论】:

    • 在最后一步之后,我确实收到了错误Loading dependency graph...jest-haste-map: @providesModule naming collision: Duplicate module name: core-js Paths: /Users/mobile/node_modules/react-native/node_modules/core-js/package.json collides with /Users/mobile/node_modules/react-native/node_modules/fbjs/node_modules/core-js/package.json
    • npm cache clean 之后做yarn install && npm dedupe 然后重启项目。看看这是否有效。
    • 我为第一次运行工作。但关闭 Xcode 并运行 react-native run-ios 后,应用程序将无法在模拟器中运行:ld: library not found for -lRealmReact clang: error: linker command failed with exit code 1 (use -v to see invocation)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 2016-12-17
    • 2023-01-23
    • 1970-01-01
    • 1970-01-01
    • 2018-03-24
    • 1970-01-01
    相关资源
    最近更新 更多