Bootstrap@4.1.1缺失Peer依赖疑问:是否需配置jQuery及构建服务器安装
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:
peerDependenciesis 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-saveonly installs jQuery temporarily on your local machine — it won't be recorded inpackage.json. That means anyone else cloning your project, or your build server runningnpm install, will hit the exact same peer dependency error you did. - The correct command here is:
This adds jQuery to your project'snpm install jquery@1.9.1-3 --savedependenciessection inpackage.json, ensuring every environment (local, build server, teammate machines) installs it automatically when runningnpm 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

