5

In an effort to save space, I've installed large packages in a common parent directory to all my projects. The scripts in these projects can refer to modules in this parent directory (see this in Node's documentation), yet npm install-ing in a freshly-cloned project pulls everything, not just the ones that the project needs on top of the ones inherited from the common parent. Are there any options to make npm install download only what it needs to?

Minimal example: consider the below file structure.

├ projects
│   ├ package.json <- specifies a dependency on `some_module^1.0.0`
│   ├ node_modules
│   │   └ some_module
│   │       └ ...
│   └ some_project
│       └ package.json <- also specifies a dependency on `some_module^1.0.0`

If npm install is run in projects/some_project, it will download some_module unconditionally.

(Note: this is not related to npm dedupe and the module duplication it solves, because this is solely a directory hierarchy: the parent directory project doesn't depend on any of the subfolders.)

concat
  • 3,107
  • 16
  • 30
  • I too would like an answer to this problem. If you `require()` something and node's [name resolution](https://nodejs.org/api/modules.html#modules_all_together) can find things in the parent directory, then why when installing would it install a duplicate locally? – ADJenks Sep 25 '19 at 03:08
  • Did you find a solution to this issue. I am in the same situation at the moment – almcaffee Nov 17 '20 at 19:38
  • @almcaffee sadly no, I've just given up and let it be, periodically clearing big node_modules from seldom-used projects. – concat Nov 17 '20 at 19:45

0 Answers0