I am trying to install the ng-bootstrap
package in my app.
I have updated all of my npm packages using npm i
as well as updating the @angular/core
and @angular/cli
modules to the latest version.
However, when I try the command npm install --save @ng-bootstrap/ng-bootstrap
, I get the following dependency error:
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
How do I interpret this message and solve the error?
From the official page, the recommended command is:
// Installation for Angular CLI
ng add @ng-bootstrap/ng-bootstrap
Try that instead of npm install
I always prefer to use the CDN instead of adding another package. I don't really know if it is the best way to do it, but for me it is okay.
Inside your main index.html
file, in the head
tag:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
And at the end of the body:
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
Okay, so I found a solution.
npm update
to update all your node packagesng --version
. As of the date of publication of this response, my version is: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
folder.package.json
and make sure that the devDependencies
match those of the installed angular clinpm i
ng add @ng-bootstrap/ng-bootstrap
Lastly you will need to install the Popper dependency if you count on installing the latest version (12.0.0 or above) of ng-bootstrap.
You can find more information on compatibility among the different versions of ng-bootstrap and the Angular CLI on the ng-bootstrap website .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.