[英]Why is my node_modules folder full of so many files I have not installed?
I'm creating a nodeJS application and struggling to upload it onto my server.我正在创建一个 nodeJS 应用程序并努力将其上传到我的服务器上。 I only have 6 dependencies yet for some reason my node_modules folder has 119 folder in it.
由于某种原因,我只有 6 个依赖项,我的 node_modules 文件夹中有 119 个文件夹。 Do I need the ones that I have not installed or have in my dependencies in my pack.json?
我是否需要那些我没有安装的或者我的 pack.json 中的依赖项?
Thanks in advance!提前致谢!
Node.js is all about modularity, and with that comes the need for a quality package manager; Node.js 完全是关于模块化的,随之而来的是对高质量 package 管理器的需求; for this purpose, npm was made.
为此,制作了 npm。 With npm comes the largest selection of community-created packages of any programming ecosystem, which makes building Node.js apps quick and easy
npm 提供了任何编程生态系统中最大的社区创建包选择,这使得构建 Node.js 应用程序变得快速和容易
Each library / dependency you add to your project must have a semantic version as 1.2.x
and can either has other dependencies used in it or none.您添加到项目中的每个库/依赖项都必须具有
1.2.x
的语义版本,并且可以在其中使用其他依赖项,也可以没有。
So if each dependency you added to your project has its own dependencies with different versions this will make the package manager you are using add them to node_modules
因此,如果您添加到项目中的每个依赖项都有其不同版本的依赖项,这将使您正在使用的 package 管理器将它们添加到
node_modules
Project dependencies with dependencies that are common and have no breaking API / semantic version are bubbled up to your node_modules
directory and the rest of dependencies versions which aren't common live in their own node_modules
directory in the libraries you added to your project具有常见依赖项且没有破坏 API / 语义版本的项目依赖项会冒泡到您的
node_modules
目录和 rest 的依赖项版本中,这些不常见的依赖项版本位于您添加到项目的库中自己的node_modules
目录中
This is a general idea of how dependencies are managed and the reason for Node.js modularity.这是有关如何管理依赖项以及 Node.js 模块化的原因的一般概念。
There are also downsides to this workflow as said by Ryan Dahl the original developer of Node.js, because node_modules
directory becomes bloated.正如 Node.js 的原始开发人员Ryan Dahl所说,此工作流程也有缺点,因为
node_modules
目录变得臃肿。
You should listen to one of his talks 10 Things I Regret About Node.js - Ryan Dahl - JSConf EU你应该听听他的演讲之一我对 Node.js 感到遗憾的 10 件事 - Ryan Dahl - JSConf EU
The dependencies you've installed are reliant on other dependencies, just like your code is dependent on the ones you've installed.您安装的依赖项依赖于其他依赖项,就像您的代码依赖于您安装的依赖项一样。
That is why there are so many other folders.这就是为什么有这么多其他文件夹的原因。
You can see a list of all the other dependencies on which the library you installed is dependent, by running:您可以通过运行以下命令查看您安装的库所依赖的所有其他依赖项的列表:
npm view (package name) dependencies
For visual learners, this concept is well demonstrated in this portion of this video .对于视觉学习者,此视频的这一部分很好地展示了这个概念。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.