乐闻世界logo
搜索文章和话题

How do I uninstall a package installed using npm link?

1个答案

1
  1. Locate the globally installed package or module: The npm link command is typically used to link a locally developed module to the global scope, enabling it to be used as if it were a published npm module during development. To uninstall this linked package, first identify its global location. The global node_modules directory is commonly found at /usr/local/lib/node_modules or ~/.npm-global/lib/node_modules.

  2. Remove the project-specific link: If you linked a package globally within a project using npm link package-name, run npm unlink package-name in the project directory to remove the link. This command eliminates the symbolic link to the global module from the project's node_modules directory.

  3. Uninstall the package globally: If you no longer need the package, execute npm unlink -g package-name or npm uninstall -g package-name to remove it globally. This action deletes the package from the global node_modules directory.

For example, if you are developing a package named "example-package" and have linked it globally using npm link, follow these steps:

First, run the following command in any project directory that uses the package:

bash
npm unlink example-package

Then, remove the global link:

bash
npm unlink -g example-package

Alternatively, uninstall it globally directly:

bash
npm uninstall -g example-package

This approach ensures that development-time package links are properly cleaned up while preventing unnecessary packages from remaining in the global environment.

2024年8月2日 14:27 回复

你的答案