I've updated node / npm which I use with my grunt projects.
However when I now want to add a package to a project myproject/
(say npm install grunt-favicon
) it seems to add hundreds of folders to myproject/node_modules/
whereas it only used to add one - normally prefixed with grunt like node_modules/grunt-favicon
.
My knowledge of these things is basic but these seem to be required dependencies, and even some of these items have even more dependencies.
Should it not be adding these dependencies somewhere else? If so how to i correct this?
I use npm 3.3.5
, node 4.1.1
, grunt-cli v0.1.13
and grunt v0.4.5
.
And this screenshot shows ~/.npm
on the left then ~/myproject/node_modules
on the right
npm install doesn't create node_modules directory.
The module structure used to be completely nested, meaning multiple versions of the same modules could be nested within each other. This is no longer the case, so module sizes are not as big as they used to be. However; lots of people still ship a tremendous amount of “fluff” with their modul...
You could remove your node_modules/ folder and then reinstall the dependencies from package. json. This would erase all installed packages in the current folder and only install the dependencies from package.
With npm or yarn, you can install a package under a custom alias. This enables you to install multiple versions of a package in the same project. Read the documentation on aliasing with npm here and yarn here.
This is correct, don't worry. You're still installing the packages locally, just the directory structure looks a bit different. It is a behaviour that changed in npm v3.0.0: now all the dependencies' dependencies are installed directly in the node_modules
folder (as far as this doesn't cause version conflicts). This greatly reduces the file tree size.
From npm 3.0.0 release notes:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With