处理有关 Bootstrap 的 'unmet peer dependency' 未在 Angular 中使用时的 NPM 警告

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

我在我的网络项目中使用 Angular 5.2.0 和 Bootstrap 4。我通过 npm i bootstrap --save 安装了 bootstrap 4,它告诉我未满足的对等依赖项:

npm WARN bootstrap@4.0.0 requires a peer of jquery@>=3.0.0 but none was installed.
npm WARN bootstrap@4.0.0 requires a peer of popper.js@^1.11.0 but none was installed.

当然,Bootstrap的JS就依赖这些对等依赖。到目前为止,一切如常。

问题是:我不使用任何 Bootstraps JS。我正在使用 ng-bootstrap,这是为 Angular.

重写的 Bootstrap 组件

这个警告让我很烦,因为它真的不是什么东西,当我不使用它时(这个项目中没有其他人应该 - 在尝试使用 Bootstrap 时出现错误原生组件非常好)。干净的代码和依赖项不应输出任何警告。

为了摆脱这个警告,我尝试了不同的方法:

所以:有什么方法可以干净地处理这些对等依赖警告吗?

遗憾的是,真正的答案是我们需要忽略警告。

ng-bootstrap 的创建者在 . They also mention that you shouldn't install the jquery or popper.js dependencies due to potential conflicts (per the setup docs 中明确指出,由于技术原因,警告是我们唯一的选择。