为什么 npm 安装的依赖项没有列在我的 package.json 文件中?

why does npm install dependences that are not listed in my package.json file?

我找不到这个问题的答案。

tl;dr... 在开始一个新的 Node/Express 项目之前,我只是 运行 npm update npm -g。当我为这个项目 运行 npm install 时,npm 安装了大量新的依赖项,这些依赖项未在我的 package.json 文件夹中列出。我以前从未见过其中的许多东西。

这里发生了什么 -- 为什么 npm 安装所有这些依赖项,我该如何解决这个问题?

我什至在上周的一个旧项目上测试了 npm install,它也有类似的行为。

ps - 有人提到即使依赖也需要依赖。像这样? http://puu.sh/ki1GW/cfead489ef.png

是的,这些是您的依赖项的依赖项。把它想象成一个树结构,你的项目是根节点。树中的所有内容都需要下载。

这里已经回答了:,但基本上没有错。不熟悉的包是你包的依赖项。 以前,它们嵌套在包的文件夹中,因此经常被忽视。从 NPM 版本 3.0.0 开始,它们不再被嵌套。

来自 NPM 3.0.0 发行说明:

Your dependencies will now be installed maximally flat. Insofar as is possible, all of your dependencies, and their dependencies, and THEIR dependencies will be installed in your project's node_modules folder with no nesting. You'll only see modules nested underneath one another when two (or more) modules have conflicting dependencies.