node.js 为什么`npm prune` 不从 node_modules 中删除文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20093791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why doesn't `npm prune` remove folders from node_modules?
提问by elanh
I have a package.jsonwith all my devDependencies.
我有package.json我所有的devDependencies.
My understanding was that if I remove a dependency, and run npm prune, node will remove the module folder from node_modules. This seems to be the easiest way to maintain my node_modulesfolder.
我的理解是,如果我删除依赖项并运行npm prune,节点将从node_modules. 这似乎是维护我的node_modules文件夹的最简单方法。
From the 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 修剪
删除无关的包
此命令删除“无关的”包。
无关包是未在父包的依赖项列表中列出的包。
However, sometimes even after running npm pruneI still have the module folder in my node_modules.
但是,有时即使在运行后npm prune,我的node_modules.
Why does this happen and what is the correct way to remove unused modules?
为什么会发生这种情况以及删除未使用模块的正确方法是什么?
回答by Andrei Karpushonak
According to documentation
根据文档
If the
--productionflag is specified, this command will remove the packages specified in yourdevDependencies.
如果
--production指定了标志,此命令将删除您的devDependencies.
So, if you want to get rid of the module folder in node_moduleswhich is specified in devDependencies, you shall execute
所以,如果你想摆脱 中node_modules指定的模块文件夹devDependencies,你应该执行
npm prune --production
npm prune --production
回答by PhilT
After running:
运行后:
npm ls
I see:
我懂了:
npm ERR! extraneous: [email protected] /path/to/package
Then when I did:
然后当我这样做时:
npm prune
The package was uninstalled.
软件包已卸载。

