gpt4 book ai didi

node.js - 为什么 `npm prune` 不从 node_modules 中删除文件夹?

转载 作者:IT老高 更新时间:2023-10-28 22:04:45 25 4
gpt4 key购买 nike

我有一个 package.json 和我所有的 devDependencies

我的理解是,如果我删除依赖项并运行 npm prune,node 将从 node_modules 中删除模块文件夹。这似乎是维护我的 node_modules 文件夹的最简单方法。

来自 docs :

npm prune

Remove extraneous packages

This command removes "extraneous" packages.

Extraneous packages are packages that are not listed on the parent package's dependencies list.

但是,有时即使在运行 npm prune 之后,我的 node_modules 中仍然有模块文件夹。

为什么会发生这种情况以及删除未使用模块的正确方法是什么?

最佳答案

根据documentation

If the --production flag is specified, this command will remove the packages specified in your devDependencies.

所以,如果你想删除 devDependencies 中指定的 node_modules 中的模块文件夹,你应该执行

npm prune --production

关于node.js - 为什么 `npm prune` 不从 node_modules 中删除文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20093791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com