2

I have a project that has a submodule which also has a submodule, each of them (root & submodule_1 & submodule_2) have a package.json.

Here is how I scaffolded my project :

|root
----|node_modules
----|package.json
----|someFolder
----|submodule_1
-------- |package.json
-------- |someFolder
-------- |submodule_2
------------ |package.json
------------ |someFolder

Is it possible to precise to npm to install each dependencies in the root node_modules ? I don’t want submodule_1 and submodule_2 to be dependencies, I just want the packages.json to be installed in the root node_modules.

If it is possible, how can I achieve this ?

Thanks for your help

GaldanM
  • 125
  • 2
  • 12
  • 2
    npm will install duplicated dependencies in root node_modules if all of them are in same version. You can read more about packages deduplication here https://docs.npmjs.com/cli/dedupe You can also do this manually by calling `npm dedupe` – ponury-kostek May 17 '18 at 13:45
  • you can install the dependencies flat with `yarn install` – andrewgi May 18 '18 at 16:08

3 Answers3

0

sorry it is not possible to precise to npm to install each dependencies in the root

0

All dependencies and subdependencies are installed in root node_modules by default, only duplicated dependencies/subdependencies are exception.

npm will install duplicated dependencies in root node_modules if all of them are/can be installed in same version.

You can read more about packages deduplication here https://docs.npmjs.com/cli/dedupe

You can also do this manually by calling npm dedupe

ponury-kostek
  • 7,824
  • 4
  • 23
  • 31
  • I think you misunderstood the question. – jstice4all May 17 '18 at 13:53
  • The thing is that when I run `npm install`, it doesn't install dependencies from submodule_1 and submodule_2's package.json. Is there something I need to precise in the root package.json ? – GaldanM May 18 '18 at 12:14
0

Well after lots of digging into npm docs and all, I realized that setting submodule_1 as a local dependency and submodule_2 as a dependency of submodule_1 was doing exactly what I wanted.

GaldanM
  • 125
  • 2
  • 12