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

如何使用Angular CLI移除通过ng add安装的包?

How to Remove Packages Installed with ng add Using Angular CLI

Great question! Let’s break this down clearly for you:

First, it’s important to note that as of now, Angular CLI doesn’t have an official, fully functional ng rm command that can seamlessly reverse the changes made by ng add—that’s exactly why your attempt with ng rm didn’t work. Remember, ng add does more than just download dependencies like npm install <package>: it uses schematics to modify your project config, add polyfills, generate package-specific initialization code, and more. Removing these packages requires reversing all those targeted changes, which can vary depending on the package you installed.

Here’s how you can properly handle the removal:

  1. Check for a package-specific removal schematic
    Some packages that support ng add also provide a dedicated schematic to clean up their changes. You can check the package’s documentation for this, or try running a command like:

    ng generate <package-name>:remove
    

    If this schematic exists, it will automatically reverse config edits, delete generated code, and clean up related dependencies for you.

  2. Manual removal (when no removal schematic exists)
    If there’s no built-in cleanup tool, you’ll need to reverse the ng add changes step by step:

    • Uninstall the core package via your package manager:
      npm uninstall <package-name>
      # Or use yarn if that's your setup
      yarn remove <package-name>
      
    • Clean up project configuration files:
      Go through files like angular.json, package.json, tsconfig.json, and polyfills.ts to remove any entries the package added (such as build configurations, scripts, polyfill imports, etc.).
    • Delete generated code:
      Remove any components, modules, or utility files that ng add created in your project. Checking your git history can help you spot exactly what was added during the installation.
    • Remove unused peer dependencies:
      If the package added extra peer dependencies during installation, uninstall those too if they’re no longer needed for your project.
  3. Verify and finalize
    After making these changes, run npm install (or yarn install) to sync your dependency tree, then test your project to ensure everything runs smoothly without the removed package.

It’s worth noting that the Angular team has discussed adding official ng remove functionality to pair with ng add, but it hasn’t been fully rolled out for all packages yet.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 07:30:53