我正在嘗試ng-bootstrap在我的應用程式中安裝該軟體包。
我已經使用和模塊npm i更新了我所有的 npm 包,并將其更新到最新版本。@angular/core@angular/cli
但是,當我嘗試命令時npm install --save @ng-bootstrap/ng-bootstrap,我收到以下依賴錯誤:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: development-toolbox@0.0.0
npm ERR! Found: @angular/core@13.3.0
npm ERR! node_modules/@angular/core
npm ERR! peer @angular/core@"13.3.0" from @angular/animations@13.3.0
npm ERR! node_modules/@angular/animations
npm ERR! peerOptional @angular/animations@"13.3.0" from @angular/platform-browser@13.3.0
npm ERR! node_modules/@angular/platform-browser
npm ERR! peer @angular/platform-browser@"13.3.0" from @angular/forms@13.3.0
npm ERR! node_modules/@angular/forms
npm ERR! @angular/forms@"~13.3.0" from the root project
npm ERR! 3 more (@angular/platform-browser-dynamic, @angular/router, the root project)
npm ERR! @angular/animations@"~13.3.0" from the root project
npm ERR! peer @angular/core@"13.3.0" from @angular/common@13.3.0
npm ERR! node_modules/@angular/common
npm ERR! peer @angular/common@"13.3.0" from @angular/forms@13.3.0
npm ERR! node_modules/@angular/forms
npm ERR! @angular/forms@"~13.3.0" from the root project
npm ERR! peer @angular/common@"13.3.0" from @angular/platform-browser@13.3.0
npm ERR! node_modules/@angular/platform-browser
npm ERR! peer @angular/platform-browser@"13.3.0" from @angular/forms@13.3.0
npm ERR! node_modules/@angular/forms
npm ERR! @angular/forms@"~13.3.0" from the root project
npm ERR! 3 more (@angular/platform-browser-dynamic, @angular/router, the root project)
npm ERR! 3 more (@angular/platform-browser-dynamic, @angular/router, the root project)
npm ERR! 5 more (@angular/forms, @angular/platform-browser, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! @ng-bootstrap/ng-bootstrap@"*" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @angular/core@13.3.9
npm ERR! node_modules/@angular/core
npm ERR! peer @angular/core@"13.3.9" from @angular/forms@13.3.9
npm ERR! node_modules/@angular/forms
npm ERR! @angular/forms@"~13.3.0" from the root project
npm ERR! peer @angular/forms@"^13.0.0" from @ng-bootstrap/ng-bootstrap@12.1.2
npm ERR! node_modules/@ng-bootstrap/ng-bootstrap
npm ERR! @ng-bootstrap/ng-bootstrap@"*" 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 D:\Users\[user]\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! D:\Users\[User]\AppData\Local\npm-cache\_logs\2022-05-25T19_32_11_969Z-debug-0.log
如何解釋此訊息并解決錯誤?
uj5u.com熱心網友回復:
從官方頁面,推薦的命令是:
// Installation for Angular CLI
ng add @ng-bootstrap/ng-bootstrap
試試這個,而不是npm install
uj5u.com熱心網友回復:
我總是更喜歡使用 CDN 而不是添加另一個包。我真的不知道這是否是最好的方法,但對我來說沒關系。
在您的主index.html檔案中,在head標簽中:
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>
在身體的末端:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
uj5u.com熱心網友回復:
好的,所以我找到了解決方案。
- 運行
npm update更新所有節點包 - 驗證 angular 的版本
ng --version。截至本回復發布之日,我的版本是:
Angular CLI: 13.3.7
Node: 16.13.1
Package Manager: npm 8.6.0
OS: win32 x64
Angular: 13.3.10
@angular-devkit/schematics 13.3.7
@angular/cli 13.3.7
@schematics/angular 13.3.7
rxjs 7.5.5
typescript 4.6.4
- 洗掉您的
node_modules檔案夾。 - 打開
package.json并確保devDependencies與已安裝的 angular cli 匹配 - 跑
npm i - 安裝 ng-boostrap:
ng add @ng-bootstrap/ng-bootstrap
最后,如果您希望安裝 ng-bootstrap 的最新版本(12.0.0 或更高版本),您將需要安裝Popper依賴項。
您可以在ng-bootstrap 網站上找到有關不同版本 ng-bootstrap 和 Angular CLI 之間兼容性的更多資訊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/481603.html
