我想安裝 vue-router 但出現一些錯誤
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/vue
npm ERR! vue@"^2.5.11" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer vue@"^3.2.0" from [email protected]
npm ERR! node_modules/vue-router
npm ERR! vue-router@"4" 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\Peyman\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\Peyman\AppData\Local\npm-cache\_logs\2022-05-31T07_48_48_170Z-debug-0.log
uj5u.com熱心網友回復:
嘗試 -
npm install --save --legacy-peer-deps
此命令將告訴 npm 忽略對等依賴項
uj5u.com熱心網友回復:
您可以使用插件也可以使用 vue-cli 添加。
嘗試vue add router
順便說一句,使用可以安裝 vuetify 和 eslint 以及更多使用的東西vue add vuetify,vue add eslint
您可以參考:https ://cli.vuejs.org/guide/plugins-and-presets.html#plugins
uj5u.com熱心網友回復:
vue問題是您的和版本不兼容vue-router。
vue@2需要vue-router@3vue@3需要vue-router@4
錯誤訊息表明您有[email protected],并且您正在嘗試安裝[email protected]. 請注意,npm install -S vue-router(沒有版本說明符)默認為當前版本latest,即.4.0.15
不要使用錯誤訊息中建議的--forceor --legacy-peer-depsnpm 標志,因為這只會安裝會導致運行時錯誤的不兼容包。
解決方案
快速修復是安裝vue-router@3:
npm install -S vue-router@3
或者您可以升級到 Vue 3,這需要卸載vue-template-compiler(Vue 2 的模板編譯器)和安裝@vue/compiler-sfc(Vue 3 的模板編譯器):
npm uninstall -S vue-template-compiler
npm install -S vue@3 @vue/compiler-sfc
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/484180.html
上一篇:在回圈中制作動態背景顏色
