【发布时间】:2021-12-05 15:22:28
【问题描述】:
我一直在开发 React Native 应用程序,但一直遇到依赖问题。我终于解决了我的依赖关系,这样我就可以真正地安装 npm 了。现在我正在尝试添加 react-native-image-mapper,当我们的应用程序使用 react 17 时,react-native-image-mapper 想要 react 16.8.3。我尝试使用该反应版本,但随后我的所有其他依赖项都关闭了。我读到 react 17 是从 16 的“逐步”升级,所以我尝试 npm i --force,但我的应用程序根本无法运行。
这里是 package.json 的依赖:
"@react-navigation/bottom-tabs": "^6.0.8",
"@react-navigation/native": "^6.0.4",
"@react-navigation/native-stack": "^6.2.2",
"@use-expo/font": "^2.0.0",
"axios": "^0.21.1",
"cloudinary": "^1.27.1",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"expo": "~42.0.1",
"expo-app-loading": "1.1.2",
"expo-camera": "^11.2.2",
"expo-font": "~9.2.1",
"expo-status-bar": "~1.0.4",
"express": "^4.17.1",
"firebase": "8.2.3",
"firebase-admin": "^9.12.0",
"morgan": "^1.9.1",
"pg": "^8.5.1",
"react": "17.0.1",
"react-native": "0.64.2",
"react-native-keyboard-aware-scroll-view": "^0.9.4",
"react-native-safe-area-context": "3.2.0",
"react-native-screens": "^3.4.0",
"react-native-select-dropdown": "^1.2.0",
"react-native-web": "^0.17.5",
"react-redux": "^7.2.4",
"redux": "^4.1.0",
"redux-devtools-extension": "^2.13.9",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"sequelize": "^6.3.5",
"uuid": "^8.3.2"
},
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/preset-react": "^7.12.10",
"@babel/register": "^7.12.10",
"babel-loader": "^8.2.2",
"eslint": "^7.32.0",
"eslint-plugin-react": "^7.26.1",
"esm": "^3.2.25",
"nodemon": "^1.19.4",
"react-dom": "17.0.1"
}
这是我尝试添加 react-native-image-mapper 时收到的错误消息:
npm ERR!
npm ERR! While resolving: mole-tracks@0.0.1
npm ERR! Found: react@17.0.1
npm ERR! node_modules/react
npm ERR! react@"17.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"16.8.3" from react-native-image-mapper@0.1.11
npm ERR! node_modules/react-native-image-mapper
npm ERR! react-native-image-mapper@"*" 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 i --force是正确的答案,如果您的应用无法运行,您必须解决依赖问题,而不是使用命令忽略它们。 -
@ridvanaltun 我该如何解决?好像每次换一个都会弹出一个错误
-
我发布了一个答案,希望对您有所帮助!
标签: node.js reactjs react-native