Complete Guide to Removing Packages in Angular CLI: From ng add to npm uninstall

Nov 22, 2025 · Programming · 8 views · 7.8

Keywords: Angular CLI | Package Removal | npm uninstall | Dependency Management | ng add

Abstract: This article provides a comprehensive exploration of package removal processes in Angular projects. It begins by analyzing the特殊性 of the ng add command in Angular CLI and its differences from npm install, then focuses on the correct steps for removing packages using npm uninstall, including deletion from package.json and node_modules. The article offers practical methods to verify successful removal operations and discusses the current lack of ng remove command in Angular 6 and later versions. Through clear code examples and step-by-step guidance, it helps developers manage project dependencies safely and efficiently.

Overview of Package Management in Angular CLI

In modern Angular development, package management is a core aspect of project maintenance. Angular CLI provides a powerful toolchain to streamline development workflows, with the ng add command introduced in Angular 6 bringing new dimensions to package installation.

The Uniqueness of ng add Command

Unlike the traditional npm install <package> command, ng add does more than just download dependencies through the package manager. It executes an installation script (implemented as a schematic) that can:

This intelligent installation approach makes ng add a more comprehensive package integration tool rather than just a simple dependency downloader.

Current State of Package Removal

Despite the powerful package installation capabilities of ng add, Angular CLI currently lacks a corresponding removal command. Executing ng help confirms that no built-in commands like ng remove or ng delete exist in current versions. This means developers cannot directly use Angular CLI to completely undo all actions performed by ng add.

Correct Approach Using npm uninstall

At the current stage, the standard method for removing packages is using npm's uninstall command:

npm uninstall <package-name>

This command performs the following operations:

Detailed Working Mechanism of npm uninstall

The npm uninstall command offers flexible removal options:

Default Behavior

By default, the command removes packages from both node_modules and package.json:

npm uninstall lodash

This completely cleans up all installation content related to the lodash package.

Preserving package.json References

If you only need to remove a package from node_modules without affecting package.json, use:

npm uninstall --no-save lodash

This is particularly useful in certain debugging scenarios.

Forcing Save Changes

When save=false is set in npm configuration, use the --save or -S flag to ensure package removal from package.json:

npm uninstall --save lodash

Verifying Uninstallation Operations

To ensure successful package removal, verify using the following methods:

On Unix systems (such as macOS):

ls node_modules

On Windows systems:

dir node_modules

Check the output to confirm that the target package directory no longer exists.

Handling Global Packages

For globally installed packages, the removal command requires the -g flag:

npm uninstall -g <package-name>

For example, to remove globally installed jshint:

npm uninstall -g jshint

Practical Application Example

Suppose we previously installed Angular Material using ng add @angular/material and now need to remove it:

npm uninstall @angular/material

This command will:

Considerations and Best Practices

When using npm uninstall, note the following:

Future Outlook

Although Angular CLI currently lacks native package removal commands, the community continues to discuss the possibility of adding ng remove functionality. Future versions may provide more complete package lifecycle management tools capable of intelligently undoing all changes made by ng add.

Conclusion

In the current Angular development environment, while ng add provides powerful package installation capabilities, package removal still relies on traditional npm toolchain. By correctly using the npm uninstall command, developers can effectively manage project dependencies, maintaining clean and maintainable codebases. Understanding how these tools work and their limitations is crucial for building robust Angular applications.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.