使用npm时出现意外行为。例如,使用命令安装express时:
npm install express
我希望将在“node_modules”目录中创建一个名为“express”的文件夹,并且其依赖项将安装在此文件夹的“node_modules”子目录中。
我看到的是正在创建“express”文件夹,但其所有依赖项都被添加到我的项目文件夹中的根“node_modules”目录(与express相同的级别)中,而不是嵌套在“express”文件夹中。
为什么会这样呢? (使用npm v3.3.5)
最佳答案
这是npm @ 3的设计更改,默认情况下会进行重复数据删除。看:
Flat, flat, flat!
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.
https://github.com/npm/npm/blob/ff47bc138e877835f1c0f419fea5f5672110678a/CHANGELOG.md#flat-flat-flat
https://github.com/npm/npm/issues/6912
关于npm node_modules是否没有正确嵌套?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32926251/