简体   繁体   English

为什么我的 node_modules 文件夹中充满了这么多我没有安装的文件?

[英]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 应用程序变得快速和容易

  • How dependencies are managed如何管理依赖项

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.

相关问题 为什么在node_modules下安装了这么多软件包? - Why are so many packages being installed under node_modules? node_modules文件夹中的许多未知模块 - Many unknown modules in node_modules folder 已安装Express,但未在node_modules文件夹中安装 - Express installed but not in node_modules folder as should be 为什么在我的phpStorm中排除了我的node_modules文件夹? - Why my node_modules folder is excluded in my phpStorm? 将CI用于Bitbucket存储库-我是否需要在根文件夹中包含node_modules? - Using CI for Bitbucket repository - do I need to have node_modules inside my root folder? 节点npm为什么将所有模块都安装在根node_modules文件夹中? - Node npm why all the modules are installed in the root node_modules folder? 我应该对我的node_modules文件夹进行硬编码吗? - Should I hard code references to my node_modules folder? AWS Elastic Beanstalk:我是否必须使用完整的“ / node_modules”和“ / bower_components”以及已编译的sass和其他依赖项来部署我的应用程序? - AWS Elastic Beanstalk: Do I have to deploy my app with full “/node_modules” and “/bower_components” and compiled sass and other dependencies? 即使我的 package.json 和 node_modules 文件夹中有它们,我也得到了未定义的包 - I'm getting undefined packages even though I have them in my package.json and node_modules folder 为什么本地安装的项目的 node_modules 文件夹与全局安装的项目之间存在差异? - Why is there a difference between the node_modules folder of a project installed locally vs globally?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM