我一直在開發 React Native 應用程式,但一直遇到依賴問題。我終于解決了我的依賴項,以便我可以實際安裝 npm。現在我正在嘗試添加 react-native-image-mapper,而我們的應用程式使用的是 react 17,而 react-native-image-mapper 想要 react 16.8.3。我嘗試使用該 React 版本,但隨后我的所有其他依賴項都關閉了。我讀到 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.
有什么簡單的方法可以解決有問題的依賴關系嗎?我們的依賴關系是否存在明顯錯誤?
我正在尋找有關如何解決此特定問題的實用建議以及避免將來發生此類事情的技巧。
uj5u.com熱心網友回復:
嘗試使用此命令
npm install --legacy-peer-deps
uj5u.com熱心網友回復:
我查看了react-native-image-mapper庫,我可以說它的結構作為一個庫很差,因此它給了你錯誤。如果您無論如何都想使用它,我建議您只需復制源代碼(只有 1 頁)并將其作為組件添加到您的專案中。
無需安裝,因為代碼中不存在本機部分。只有 JavaScript。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/322522.html
