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

How to remove a package from pnpm store, or force re-download it?

1个答案

1

pnpm is a package manager similar to npm and yarn, but it manages package storage in its own unique way. When you want to remove a package from the local store or force re-download a package, follow these steps:

Removing a Specific Package from the Local Store

If you need to remove a specific package from pnpm's global store, you can use the pnpm store prune command. This command removes all packages not referenced by the project's package.json file.

However, if you want to remove a specific package, you can manually navigate to pnpm's store directory and delete the corresponding content. pnpm's store directory is usually found at ~/.pnpm-store.

For example, to remove the lodash package from the local store, you can:

  1. Locate the position of the lodash package in the local store.
  2. Directly delete the relevant files and folders at that location.

Note that directly manipulating the file system may cause inconsistency in pnpm's state, so proceed with caution.

Force Re-downloading a Package

If you want to force re-download a package (i.e., make pnpm ignore existing cache), you can use the pnpm install command with the --force parameter.

For example, to re-download the express package, run the following command:

sh
pnpm install express --force

This command tells pnpm to ignore the cache in the local store and download the latest version of the express package from the remote repository.

Consider another practical scenario: while developing a project, if you discover that a dependency package has an issue, you may need to remove it so that the next pnpm install downloads a new copy. In this case, besides using the --force parameter, you can first remove the dependency using pnpm remove, then add it again:

sh
# Remove dependency pnpm remove lodash # Re-add dependency, which will download the latest version pnpm add lodash

This will make pnpm download the latest version of the lodash package from the remote repository.

Conclusion

To remove packages from the pnpm local store or force re-download, you can use pnpm store prune to clean unused packages, directly delete files and folders in the store, or use the install command with the --force parameter to ignore cache. In practice, proceed with caution to ensure that you do not disrupt other dependencies or the normal operation of projects.

2024年6月29日 12:07 回复

你的答案