Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle NPM warning about Bootstrap's 'unmet peer dependency' when they are not used in Angular

I'm using Angular 5.2.0 together with Bootstrap 4 in my web project. I installed bootstrap 4 via npm i bootstrap --save and it told me about unmet peer dependencies:

npm WARN [email protected] requires a peer of jquery@>=3.0.0 but none was installed.
npm WARN [email protected] requires a peer of popper.js@^1.11.0 but none was installed.

Of course, Bootstrap's JS relies on these peer dependencies. So far, so usual.

The thing is: I don't use any of Bootstraps JS. I'm using ng-bootstrap which are the Bootstrap Components rewritten for Angular.

This warning annoys me, because it really isn't a thing, when I'm not using it anyway (and nobody else in this project should - getting an error when trying to use Bootstrap's components natively is perfectly fine). Clean code and dependencies should not output any warnings.

To get rid of this warning, I tried different :

  • Find an npm-package which only contains Bootstrap's SCSS. There is at least one but it still uses Bootstrap's version 3. Furthermore, there is no way to tell, when these packages get updated, so I prefer to use the original bootstrap package.
  • Just install the dependencies and not use them. This results in dependencies in the package.json which are not used - and should (imho) also be avoided in a Clean Code environment.
  • Silence the warnings from yarn/npm (I'v recently switched to yarn, but the errors are similar). Probably not a good idea, warnings are usually useful... There seems to be also consensus, that one should not be able to switch off specific warnings. I kinda agree.
    • Ignore them. Not an option for me - as mentioned above, a clean build proess should not return warnings.

So: Is there any way to handle these peer dependency warnings in a clean manner?

like image 936
Florian Gössele Avatar asked Apr 09 '18 11:04

Florian Gössele


People also ask

What is unmet Peer dependency npm?

UNMET PEER DEPENDENCY error is thrown when the dependencies of one or more modules specified in the package. json file is not met. Check the warnings carefully and update the package. json file with correct versions of dependencies. Then run rm -rf node_modules/ npm cache clean npm install.

How do you resolve peer dependencies?

Solution 1: Ignore the peerDependencies The easiest way to fix the issue is to pass an additional parameter –legacy-peer-deps to npm install. The --legacy-peer-deps tells the npm to ignore the peer dependencies and continue the installation of the package.

Does npm install peer dependencies?

CLI command to install npm peerDependencies. This can be useful when developing modules. If you run this npm-install-peers command, moment will be installed because it's a direct peer dependency of your project.

What is npm Peer dependency?

Peer Dependencies are used to specify that our package is compatible with a specific version of an npm package. Good examples are Angular and React. To add a Peer Dependency you actually need to manually modify your package.json file.


1 Answers

Sadly, the real answer is that we need to just ignore the warnings.

The creator of ng-bootstrap explicitly states that the warnings are our only option due to technical reasons in this answer. They also mention that you shouldn't install the jquery or popper.js dependencies due to potential conflicts (per the setup docs).

like image 112
bsplosion Avatar answered Sep 20 '22 17:09

bsplosion