【问题标题】:Using expo to install a package with NPM fails使用 expo 安装带有 NPM 的包失败
【发布时间】:2021-10-31 23:27:57
【问题描述】:

我正在尝试使用 expo 下载 @react-native-community/slider。这样做会失败

世博版本:4.12.10 NPM 版本:最新(8.1.2)

我了解到您应该在 https://github.com/callstack/react-native-slider/issues/333 上添加 --legacy-peer-deps

但是,你不能通过 expo 做到这一点。

powershell 输出日志

PS C:\Users\15154\Downloads\Projects\demo> npm install -g npm@latest
C:\Users\15154\AppData\Roaming\npm\npm -> C:\Users\15154\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
C:\Users\15154\AppData\Roaming\npm\npx -> C:\Users\15154\AppData\Roaming\npm\node_modules\npm\bin\npx-cli.js
+ npm@8.1.2
added 70 packages from 18 contributors, removed 289 packages and updated 148 packages in 20.49s


   ╭───────────────────────────────────────────────────────────────╮
   │                                                               │
   │     New major version of npm available! 6.14.15 -> 8.1.2      │
   │   Changelog: https://github.com/npm/cli/releases/tag/v8.1.2   │
   │               Run npm install -g npm to update!               │
   │                                                               │
   ╰───────────────────────────────────────────────────────────────╯

PS C:\Users\15154\Downloads\Projects\demo> npm -v
8.1.2
PS C:\Users\15154\Downloads\Projects\demo> expo install @react-native-community/slider
Installing 1 SDK 43.0.0 compatible native module 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@17.0.1
npm ERR! node_modules/react
npm ERR!   react@"17.0.1" from the root project
npm ERR!   peer react@"*" from @react-native-community/slider@4.1.7
npm ERR!   node_modules/@react-native-community/slider
npm ERR!   1 more (react-native)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17.0.2" from react-native-windows@0.66.2
npm ERR! node_modules/react-native-windows
npm ERR!   peer react-native-windows@"*" from @react-native-community/slider@4.1.7
npm ERR!   node_modules/@react-native-community/slider
npm ERR!     @react-native-community/slider@"4.1.7" 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 C:\Users\15154\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\15154\AppData\Local\npm-cache\_logs\2021-10-31T23_22_12_319Z-debug.log

npm exited with non-zero code: 1
Error: npm exited with non-zero code: 1
    at ChildProcess.completionListener (C:\Users\15154\AppData\Roaming\npm\node_modules\expo-cli\node_modules\@expo\spawn-async\src\spawnAsync.ts:65:13)
    at Object.onceWrapper (node:events:510:26)
    at ChildProcess.emit (node:events:390:28)
    at ChildProcess.cp.emit (C:\Users\15154\AppData\Roaming\npm\node_modules\expo-cli\node_modules\cross-spawn\lib\enoent.js:34:29)
    at maybeClose (node:internal/child_process:1064:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
    ...
    at Object.spawnAsync [as default] (C:\Users\15154\AppData\Roaming\npm\node_modules\expo-cli\node_modules\@expo\spawn-async\src\spawnAsync.ts:26:19)
    at NpmPackageManager._runAsync (C:\Users\15154\AppData\Roaming\npm\node_modules\expo-cli\node_modules\@expo\package-manager\src\NodePackageManagers.ts:166:31)
    at NpmPackageManager.addAsync (C:\Users\15154\AppData\Roaming\npm\node_modules\expo-cli\node_modules\@expo\package-manager\src\NodePackageManagers.ts:105:18)
    at actionAsync (C:\Users\15154\AppData\Roaming\npm\node_modules\expo-cli\src\commands\installAsync.ts:122:3)

非常感谢您的帮助

【问题讨论】:

    标签: react-native npm expo


    【解决方案1】:

    先安装npm包再使用expo命令:

    npm i --save @react-native-community/slider --legacy-peer-deps
    expo install @react-native-community/slider
    

    看起来这对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 2018-05-11
      • 1970-01-01
      相关资源
      最近更新 更多