无法解析依赖树 - React Native Expo

Posted

技术标签:

【中文标题】无法解析依赖树 - React Native Expo【英文标题】:Unable to resolve dependency tree - React Native Expo 【发布时间】:2021-07-12 12:00:09 【问题描述】:

我的故事是从 React Native (Expo) 开始的。有一天我需要安装datetimepicker。不幸的是,我做错了什么。我试图自己面对这个问题。我删除了node_modeles 目录和package.lock.json。当我尝试npm install 时,出现以下错误:

错误信息

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: undefined@undefined
npm ERR! Found: react@16.13.1
npm ERR! node_modules/react
npm ERR!   react@"16.13.1" from the root project
npm ERR!   peer react@">=16.8.3" from @react-native-community/datetimepicker@3.4.6
npm ERR!   node_modules/@react-native-community/datetimepicker
npm ERR!     @react-native-community/datetimepicker@"^3.0.4" from the root project
npm ERR!   1 more (react-native)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17.0.1" from react-native-windows@0.64.3
npm ERR! node_modules/react-native-windows
npm ERR!   peer react-native-windows@">=0.62" from @react-native-community/datetimepicker@3.4.6
npm ERR!   node_modules/@react-native-community/datetimepicker
npm ERR!     @react-native-community/datetimepicker@"^3.0.4" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

我知道这是依赖版本错误的问题,但我不知道如何修复它:( 那是我的 package.json。

更新package.json


  "main": "node_modules/expo/AppEntry.js",
  "scripts": 
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  ,
  "dependencies": 
    "@react-native-async-storage/async-storage": "^1.13.0",
    "@react-native-picker/picker": "1.9.11",
    "@react-navigation/bottom-tabs": "^5.11.10",
    "@react-navigation/drawer": "^5.12.5",
    "@react-navigation/native": "^5.9.4",
    "@react-navigation/stack": "^5.14.4",
    "@types/expo__vector-icons": "^9.0.1",
    "expo": "~41.0.0",
    "expo-app-loading": "^1.0.3",
    "expo-notifications": "~0.11.5",
    "expo-sms": "~9.1.2",
    "expo-status-bar": "~1.0.4",
    "i18n-js": "^3.8.0",
    "moment": "^2.29.1",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",
    "react-native-gesture-handler": "~1.10.2",
    "react-native-pager-view": "5.0.12",
    "react-native-reanimated": "~1.13.0",
    "react-native-safe-area-context": "3.2.0",
    "react-native-screens": "~3.0.0",
    "react-native-tab-view": "^3.0.1",
    "react-native-web": "^0.13.18",
    "react-native-webview": "11.2.3",
    "react-navigation-header-buttons": "^7.0.1",
    "react-redux": "^7.2.3",
    "redux": "^4.0.5",
    "redux-thunk": "^2.3.0"
  ,
  "devDependencies": 
    "@babel/core": "~7.9.0",
    "@types/i18n-js": "^3.8.0",
    "@types/react": "~16.9.35",
    "@types/react-dom": "^17.0.3",
    "@types/react-native": "~0.63.2",
    "@types/react-redux": "^7.1.16",
    "typescript": "~4.0.0"
  ,
  "private": true

我怎样才能让它再次工作?


更新 #1

我创建了一个新项目,并通过 expo install 安装了所有依赖项,没有 react-native-modal-datetime-picker。我已经复制并依赖于我的原始项目。当我使用 npm install 时,我的项目已正确安装并显示以下消息:

22:39 $ npm install
npm WARN deprecated deep-assign@3.0.0: Check out `lodash.merge` or `merge-options` instead.
npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated uglify-es@3.3.9: support for ECMAScript is superseded by `uglify-js` as of v3.13.0
npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
npm WARN deprecated core-js@1.2.7: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated core-js@2.6.12: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated core-js@2.6.12: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated core-js@2.6.12: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated core-js@2.6.12: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated core-js@2.6.12: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.

added 1087 packages, and audited 1088 packages in 30s

60 packages are looking for funding
  run `npm fund` for details

12 low severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

现在我正在尝试安装 react-native-modal-datetime-picker (https://github.com/mmazzarolo/react-native-modal-datetime-picker),但出现错误:

22:44 $ expo install react-native-modal-datetime-picker @react-native-community/datetimepicker
Installing 1 SDK 41.0.0 compatible native module and 1 other package using npm.
> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: undefined@undefined
npm ERR! Found: react@16.13.1
npm ERR! node_modules/react
npm ERR!   react@"16.13.1" from the root project
npm ERR!   peer react@">=16.8.3" from @react-native-community/datetimepicker@3.2.0
npm ERR!   node_modules/@react-native-community/datetimepicker
npm ERR!     @react-native-community/datetimepicker@"3.2.0" from the root project
npm ERR!   1 more (react-native)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17.0.1" from react-native-windows@0.64.3
npm ERR! node_modules/react-native-windows
npm ERR!   peer react-native-windows@">=0.62" from @react-native-community/datetimepicker@3.2.0
npm ERR!   node_modules/@react-native-community/datetimepicker
npm ERR!     @react-native-community/datetimepicker@"3.2.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /home/adas/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/adas/.npm/_logs/2021-04-17T20_53_05_643Z-debug.log

npm exited with non-zero code: 1
Error: npm exited with non-zero code: 1
    at ChildProcess.completionListener (/home/adas/.nvm/versions/node/v14.16.0/lib/node_modules/expo-cli/node_modules/@expo/spawn-async/src/spawnAsync.ts:65:13)
    at Object.onceWrapper (events.js:422:26)
    at ChildProcess.emit (events.js:315:20)
    at ChildProcess.EventEmitter.emit (domain.js:467:12)
    at maybeClose (internal/child_process.js:1048:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
    ...
    at Object.spawnAsync [as default] (/home/adas/.nvm/versions/node/v14.16.0/lib/node_modules/expo-cli/node_modules/@expo/spawn-async/src/spawnAsync.ts:26:19)
    at NpmPackageManager._runAsync (/home/adas/.nvm/versions/node/v14.16.0/lib/node_modules/expo-cli/node_modules/@expo/package-manager/src/NodePackageManagers.ts:166:31)
    at NpmPackageManager.addAsync (/home/adas/.nvm/versions/node/v14.16.0/lib/node_modules/expo-cli/node_modules/@expo/package-manager/src/NodePackageManagers.ts:105:18)
    at installAsync (/home/adas/.nvm/versions/node/v14.16.0/lib/node_modules/expo-cli/src/commands/install.ts:130:3)
    at Command.<anonymous> (/home/adas/.nvm/versions/node/v14.16.0/lib/node_modules/expo-cli/src/exp.ts:349:7)

【问题讨论】:

我遇到了完全相同的问题。我只是想知道我是否发布了这个问题并忘记了它。 【参考方案1】:

尝试将软件包更新到最新版本。

npm update

如果更新不起作用,请尝试使用--force 标志进行安装。例如:

npm install --force

【讨论】:

您可以使用 --force 标志来接受警告。希望这会奏效! --force float 和 npm install 为我工作【参考方案2】:

尝试运行这个:

npm install --legacy-peer-deps --global expo-cli

【讨论】:

以上是关于无法解析依赖树 - React Native Expo的主要内容,如果未能解决你的问题,请参考以下文章

无法解析模块 @react-native-masked-view/masked-view 2021

无法解析模块'./core/theming' React-native cli

无法解析依赖树 Reactjs

npm install react-native-paper 期间的问题

ERESOLVE 无法解析依赖树

React-Native Metro 捆绑器无法提供任何文件