【问题标题】:Duplicate module name: react重复的模块名称:反应
【发布时间】:2019-06-21 05:29:23
【问题描述】:

我有一个带有以下package.json 文件的react-native 项目:

{
  "name": "react-native-paper-example",
  "version": "0.0.1",
  "description": "Example for React Native Paper",
  "author": "",
  "private": true,
  "scripts": {
    "flow": "flow",
    "start": "expo start",
    "android": "expo android",
    "ios": "expo ios"
  },
  "main": "node_modules/expo/AppEntry.js",
  "dependencies": {
    "@expo/vector-icons": "^9.0.0",
    "create-react-context": "^0.2.3",
    "expo": "^32.0.0",
    "expo-core": "^2.0.0",
    "expo-font": "^2.0.0",
    "query-string": "^6.2.0",
    "react": "16.7.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
    "react-native-paper": "^2.4.0",
    "react-native-svg": "^9.0.5",
    "react-navigation": "^3.0.9"
  },
  "devDependencies": {
    "babel-plugin-module-resolver": "^3.1.1",
    "babel-preset-expo": "^5.0.0",
    "expo-cli": "^2.3.8",
    "flow-bin": "^0.91.0"
  },
  "resolutions": {
    "**/create-react-context": "0.2.3",
    "**/hoist-non-react-statics": "2.5.0",
    "**/react-lifecycles-compat": "3.0.4",
    "**/react": "16.5.0"
  }
}

要安装我运行的模块:

$ yarn install

我的问题是当我跑步时:

$ expo start

我收到以下错误:

[02:30:45] Your app is running at exp://192.168.1.194:19000
Logs for your project will appear below. Press Ctrl+C to exit.
[02:30:56] (node:6184) UnhandledPromiseRejectionWarning: Error: jest-haste-map: @providesModule naming collision:
[02:30:56]   Duplicate module name: react
[02:30:56]   Paths: D:\react-native-app\node_modules\create-react-context\node_modules\react\package.json collides with D:\react-native-app\node_modules\react\package.json
[02:30:56]
[02:30:56] This error is caused by a @providesModule declaration with the same name across two different files.
[02:30:56]     at setModule (D:\react-native-app\node_modules\jest-haste-map\build\index.js:462:17)
[02:30:56]     at workerReply (D:\react-native-app\node_modules\jest-haste-map\build\index.js:512:9)
[02:30:56]     at <anonymous>
[02:30:56]     at process._tickCallback (internal/process/next_tick.js:188:7)
[02:30:56] (node:6184) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
[02:30:56] (node:6184) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

知道如何解决这个问题吗?

谢谢!

【问题讨论】:

    标签: javascript react-native react-navigation jsx expo


    【解决方案1】:

    您可能应该从您的解决方案中删除此行 "**/react": "16.5.0",因为它与您指定为依赖项的反应版本不兼容:"react": "16.7.0",

    【讨论】:

    • 删除该分辨率后,删除目录:node_modules 并再次完成:$ yarn install,我做了:$ expo start 并收到以下错误:Unable to resolve "schedule/tracking" from "node_modules\react-native\Libraries\Renderer\oss\ReactNativeRenderer-dev.js"。关于如何解决这个问题的任何想法?谢谢。
    • 这似乎与react中将schedule/tracking的名称更改为schedule/tracing有关。您有两个选择:1. 更新您的 react-native 版本 2. 使用 yarn add react@16.5.1 将 react 降级到 16.5.1
    • 我喜欢更新/升级东西的想法。那么,我需要做什么才能选择更新选项?
    • 这是更难的方法,因为该错误已在 RN 0.57.3 中修复,但显然 expos sdk v32.0.0 是基于 RN 0.57.x 版本 expo version 32.0.1 并希望修复合并到那里。因此,作为 expo 32.0.0 锁定基础的 RN 0.57 版本严格响应 16.5.0。我建议将 react 降级到 16.5.1 并相应地升级到您的 RN 和 expo 版本,而不是相反。
    • 您也可以查看我的stackoverflow answer to similiar question
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    相关资源
    最近更新 更多