无法使用 npm 更新 React 和 React Native

Jae*_*eSo 3 npm react-native

我正在尝试更新到react@17.0.1和react-native@0.64.0-rc.0,但遇到以下错误:

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! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17.0.1" from react-native@0.64.0-rc.0
npm ERR! node_modules/react-native
npm ERR!   react-native@"0.64.0-rc.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.
Run Code Online (Sandbox Code Playgroud)

我目前使用的是 React 16.13.1 和 React Native 0.63.4。关于如何解决这个问题有什么想法吗?

只是用 --verbose 运行它并得到了这个:

npm notice 
npm verb stack Error: unable to resolve dependency tree
npm verb stack     at Arborist.[failPeerConflict] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1143:25)
npm verb stack     at Arborist.[placeDep] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:1242:32)
npm verb stack     at /usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:851:46
npm verb stack     at Array.map (<anonymous>)
npm verb stack     at Arborist.[buildDepStep] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:851:8)
npm verb stack     at processTicksAndRejections (node:internal/process/task_queues:94:5)
npm verb stack     at async Arborist.buildIdealTree (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:209:7)
npm verb stack     at async Promise.all (index 1)
npm verb stack     at async Arborist.reify (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:131:5)
npm verb stack     at async Install.install (/usr/local/lib/node_modules/npm/lib/install.js:120:5)
npm verb cwd /Users/x/Development/App
npm verb Darwin 20.3.0
npm verb argv "/usr/local/Cellar/node/15.9.0/bin/node" "/usr/local/bin/npm" "install" "react@17.0.1" "--verbose"
npm verb node v15.9.0
npm verb npm  v7.6.2
Run Code Online (Sandbox Code Playgroud)

Tro*_*ott 6

您可能正在运行 npm 版本 7。如果是这样,请尝试npm install使用--legacy-peer-deps.

npm 版本 6 对依赖冲突采取了相对宽松的方法,而 npm 版本 7 更加严格,因此在 npm 6 没有的情况下会失败。要返回 npm 6 依赖项解析算法,请使用该--legacy-peer-deps标志。另一种选择是降级到 npm 6。