我正在尝试在react-native中使用react-三纤维。当我尝试按照手册安装并运行它时,出现以下错误。
当我运行 npm install 时,出现以下错误。你能告诉我为什么会出现这种情况吗?
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR! react@"18.2.0" from the root project
npm ERR! peer react@"*" from @react-native/[email protected]
npm ERR! node_modules/@react-native/virtualized-lists
npm ERR! @react-native/virtualized-lists@"0.74.85" from [email protected]
npm ERR! node_modules/react-native
npm ERR! react-native@"0.74.3" from the root project
npm ERR! 2 more (@react-native/virtualized-lists, @react-three/fiber)
npm ERR! 9 more (@react-three/fiber, react-use-measure, its-fine, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^18.3.1" from [email protected]
npm ERR! node_modules/react-dom
npm ERR! peerOptional react-dom@">=18.0" from @react-three/[email protected]
npm ERR! node_modules/@react-three/fiber
npm ERR! @react-three/fiber@"^8.16.8" from the root project
npm ERR! peer react-dom@">=16.13" from [email protected]
npm ERR! node_modules/@react-three/fiber/node_modules/react-use-measure
npm ERR! react-use-measure@"^2.1.1" from @react-three/[email protected]
npm ERR! node_modules/@react-three/fiber
npm ERR! @react-three/fiber@"^8.16.8" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/react
npm ERR! peer react@"^18.3.1" from [email protected]
npm ERR! node_modules/react-dom
npm ERR! peerOptional react-dom@">=18.0" from @react-three/[email protected]
npm ERR! node_modules/@react-three/fiber
npm ERR! @react-three/fiber@"^8.16.8" from the root project
npm ERR! peer react-dom@">=16.13" from [email protected]
npm ERR! node_modules/@react-three/fiber/node_modules/react-use-measure
npm ERR! react-use-measure@"^2.1.1" from @react-three/[email protected]
npm ERR! node_modules/@react-three/fiber
npm ERR! @react-three/fiber@"^8.16.8" 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!
npm ERR! For a full report see:
npm ERR! /Users/m/.npm/_logs/2024-07-16T16_01_32_801Z-eresolve-report.txt
npm ERR! A complete log of this run can be found in: /Users/m/.npm/_logs/2024-07-16T16_01_32_801Z-debug-0.log
我就这样安装完成了,一切都按照说明书进行。
但是,当我运行npm install时,出现错误,我不知道为什么会出现这种情况。你能给我一些建议吗?
1. npx react-native init temp --template react-native-template-typescript --pm npm
2. npx install-expo-modules@latest
3. expo install expo-gl
4. npm install three @react-three/fiber
5. make file in project root > metro.config.js.
module.exports = {
resolver: {
sourceExts: ['js', 'jsx', 'json', 'ts', 'tsx', 'cjs', 'mjs'],
assetExts: ['glb', 'gltf', 'png', 'jpg'],
},
}
6. npm install <<<<< error return
我终于找到了一种适合我的方法,方法是将react版本更改为18.2.0,然后安装react-dom,这样两个版本都是一样的
"react": "18.2.0",
"react-dom": "18.2.0"
我认为最新版本的 React 不支持 React-Native-Fiber 或者有问题
我不知道这是正确的方法,但对我有用