F
F
Finesse2015-07-14 16:46:26
Node.js
Finesse, 2015-07-14 16:46:26

How to force NPM not to include dependencies multiple times?

As a result of executing the command npm install, a directory with the package is obtained, which contains all its dependencies. Moreover, absolutely all dependencies are included, even if they are already installed globally. And sometimes one package is included in the list of dependencies several times:

user$ npm ls -g
/usr/local/lib
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]

As a result, packages that perform simple functions weigh tens of megabytes.
Actually, the question is: is it possible to somehow install the package so that the packages already in the dependencies are not copied, but connected by a link? If not, is there an alternative that doesn't consume disk space as much?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2015-07-14
@Finesse

even if they are already installed globally

Installing packages globally has not been recommended since node 0.6, EMNIP. So even if it's installed globally, npm will still install it locally.
That's right, npm saves you from dependency hell. Today has-ansi and strip-ansi require the same version of ansi-regex, and tomorrow has-ansi requires 3.x already - this is already a conflict and you will have to move ansi-regex back inside. Similarly with globally installed packages. But what if we are talking about a library that requires dozens of your only first-level dependencies (for example, underscore or lodash), and everyone has a different version?
In npm 3, they promise to make the dependency tree as flat as possible, perhaps there will be some kind of optimization on this topic - try it, there is already a beta.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question