Reputation: 45464
My node package currently requires express
and locomotive
. Both express
and locomotive
require the commander
package.
When each package (express
and locomotive
) requires commander, this will resolve to two different files. Based on Node's documentation, the commander
package will get executed twice and there will be two master copies of the commander
package, one for each file, within my app.
Now, based on my understanding of require.resolve()
, require() will search up the directory tree all the way up to the machine's root directory (or as far up as the user is allowed) and look in every single directory along the way for ./node_modules/commander
.
Should I then consolidate the commander
package (and all other duplicate packages) into the node_modules
folder at the root of my app?
EDIT 12:58 p.m.: I also noticed that the duplicate packages may not be of the same version. express
has commander 0.6.1
while locomotive
has commander 1.0.4
. Another dependency express
and locomotive
share is mkdirp
at 0.3.3
and 0.3.4
, respectively.
Upvotes: 0
Views: 265
Reputation: 3639
Each package installs its own dependencies in their respective node_modules
folder on installation.
For instance, express
would have it's own node_modules
folder with it's specific version of commander
in it, and the other module would have it's own.
To confirm;
mkdir someNewProject && cd someNewProject
npm install express locomotive
Then see the directory structure of those installed modules with something like this;
ls node_modules/express
ls node_modules/locomotive
You should notice they each have their own node_modules
folders with their dependencies. Therefore, I would not advise trying to make a common commander package.
Upvotes: 2