"npm install" installs all dependencies in node_modules directory, instead of having them nested "npm install" installs all dependencies in node_modules directory, instead of having them nested laravel laravel

"npm install" installs all dependencies in node_modules directory, instead of having them nested


Update: As Erik Pukinskis mentioned in the comments: As of npm 3.5, support for --legacy-bundling has been dropped.


Yes, there is a way to have nested directories again by changing npm's (version 3 as of this writing) default behaviour:

  1. Delete the currently present node_modules folder.

  2. Tell npm to install with legacy bundling for this one install:

    npm install --legacy-bundling

A "permanent" alternative:

  1. Set your npm config to always use legacy bundling...

    npm set legacy-bundling=true

  2. .. and run as usual:

    npm install

Note: fetching dependencies with legacy bundling will take a lot more time because many several different versions of the same dependencies will be installed.

Disclaimer: As a non-Windows user I have no need for flat dependencies and want to find self-declared dependencies with ease in favour of automatic deduping. Since installing npm dependencies without legacy bundling already takes an incredible amount of time I'm usually willing to spend those extra minutes install time. It gets back down to 5 directories from previously 700+ (...) in a Laravel Elixir setup with bootstrap (non-sass), font-awesome and jquery added.


That's the new behavior of npm 3 as per this npm blog.