Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
604 views
in Technique[技术] by (71.8m points)

module - how can I force npm 3 to install nested dependencies?

I just upgraded to npm version 3 and noticed one of the biggest changes it made is that it enforces a flat dependency tree.

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.

So for example if package A is dependent on package B, when you npm install A you will get this file structure:

--- root/
 |--- node_modules/
   |--- A/
   |--- B/

instead of the old file structure from version 2 or lower:

--- root/
 |--- node_modules/
   |--- A/
     |--- node_modules/
       |--- B/

The first (and I’m sure not the last) problem I ran into was this:

Package A isn’t aware of npm v3’s behavior and is dependent on package B. But A assumes the old (v2) file structure because it has node_modules/B in its code, instead of the proper ../node_modules/B. Now the code from A won’t compile because it’s looking for B/ in the wrong directory.

If I don’t feel like nagging the developer to fix the code and waiting for an update of A, I wonder if there’s a way I can set an option that will force npm to install A’s dependencies inside its own node_modules folder, the same way npm v2 would have done it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Have you tried --legacy-bundling for npm install?

https://docs.npmjs.com/cli/install

The --legacy-bundling argument will cause npm to install the package such that versions of npm prior to 1.4, such as the one included with node 0.8, can install the package. This eliminates all automatic deduping.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...