Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / Node.js

How to install node modules nested with npm@3, as npm@2 did

1.00/5 (1 vote)
31 Jan 2016CPOL 10.8K  
Using the --legacy-building flag

Introduction

Managing packages with npm (a.k.a. nod package manager) recently experienced some major changes.
While npm version 2 stored dependent packages in a deeply nested folder tree, version 3 will flatten the dependency folder structure as much as possible.

In general, I am a great fan of this new behavior. For some special cases there may be a reason to stick with the older structure, at least for some time. E.g. for some existing packages may still rely on the nested structure.

Using the code

A rather straight froward approach is already implemented in npm@3, but it is well hidden somewhere in the backrooms of documentation [^]. A google search today brought up some unconventional and impractical ideas. So I wanted to share this hint with you:

Using the --legacy-bundling flag will install packages in the well-known deeply nested structure.

npm install --legacy-bundling

This stops any flattening or deduping functionality.

If you happen to have trouble with legacy packages, probalby this can help you. If not, just please ignore this tip and enjoy the flattened, deduped node modules structure ;)

History

Keep a running update of any changes or improvements you've made here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)