You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bootstrap@4.1.1缺失Peer依赖疑问:是否需配置jQuery及构建服务器安装

Peer Dependencies & Bootstrap in Angular: Your Questions Answered

Hey there! Since you're new to npm and Angular projects, let's walk through your questions clearly:

1. Should you add jquery@1.9.1-3 to peerDependencies?

Short answer: No — you should install it as a regular project dependency instead. Here's why:

  • peerDependencies is designed for library authors, not end-users building applications. It tells other developers who use your library that they need to have certain dependencies already set up in their own projects. Since you're building an Angular app that directly uses Bootstrap, this isn't your use case.
  • Using --no-save only installs jQuery temporarily on your local machine — it won't be recorded in package.json. That means anyone else cloning your project, or your build server running npm install, will hit the exact same peer dependency error you did.
  • The correct command here is:
    npm install jquery@1.9.1-3 --save
    
    This adds jQuery to your project's dependencies section in package.json, ensuring every environment (local, build server, teammate machines) installs it automatically when running npm install.

2. Does the build server need this peer dependency?

Absolutely — but if you follow the step above (adding jQuery to dependencies), you won't need to do anything extra. When your build server runs npm install, it will read package.json and install all listed dependencies, including jQuery. If you only used --no-save locally, the build server will still throw the same peer dependency error because jQuery won't be installed there.

Quick extra tip for Angular + Bootstrap

Since you're using Angular, you might need to configure angular.json to include Bootstrap's CSS and JS files (plus jQuery) so they're loaded in your app. For example, add the path to Bootstrap's CSS in the styles array, and paths to jQuery and Bootstrap's JS files in the scripts array. This is optional based on how you're using Bootstrap in your project, but it's a common step to get Bootstrap working properly in Angular.

内容的提问来源于stack exchange,提问作者dev27

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:27:00