问题
I am trying to spin up a node service on my mac. When I run npm install in the folder where my node service is, it is installing modules which are not mentioned in my package.json. There are extra modules which I am not expecting and some modules that I expect are missing. What could be the reason? How does the node modules folder get created. Does it use any global set up? I am a newbie to nodejs and any help will be appreciated.
回答1:
Well, it has been introduced with npm3 (https://github.com/npm/npm/blob/master/CHANGELOG.md#v300-2015-06-25):
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.
回答2:
I believe this is something new that happened in the newest version of npm.
If I'm not mistaken, it's installing all the dependencies flat instead of nested inside of whichever module that needs it.
来源:https://stackoverflow.com/questions/33520581/node-js-adding-unwanted-modules-when-i-do-npm-install