2

I have a node projection which has a dependency let's say depA. After I run yarn install on my project, it downloads all dependencies for depA in node_modules/depA/node_modules which makes the node_modules directory very big. It doesn't download this folder for other dependencies. Is there anything I should look at why it happens on depA?

3
  • Generally Yarn/NPM does that if there are conflicts between the versions of transitive dependencies depA needs and the versions your other dependencies need. Commented Aug 26, 2020 at 8:12
  • I see the node_modules directory is pretty big. Does it download all dependencies or just download the conflicts dependencies? Commented Aug 26, 2020 at 8:23
  • Does this answer your question? How to prevent nested node_modules inside node_modules Commented Aug 26, 2020 at 8:26

1 Answer 1

2

Its how dependencies get installed in node.js, a folder with name node_modules is created and then all dependency mentioned in your package.json is fetched from npm server and downloaded.

Now comes the twist, say in your package.json has dependency depA only. but library depA internally is dependent on depSubA, depSubB then these 2 will also get downloaded so that depA can work.

In the previous version of npm (before 5 I guess), there used to be subfolders inside node_modules which had their independent dependencies creating chances of duplicities and huge folder, the latest version now shares these common dependencies.

check for more details https://docs.npmjs.com/configuring-npm/folders.html

Sign up to request clarification or add additional context in comments.

4 Comments

Does every dependency under depA download its own dependencies? Why only depA downloads but not others?
if depA has a dependency on depSubA it will be downloaded
Is there a way to stop downloading these nested dependencies?
No, that is how node dependencies work, DENO is going to answer this problem

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.