Joey Yi Zhao
Joey Yi Zhao

Reputation: 42490

Why yarn install downloads node_modules for dependency?

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?

Upvotes: 2

Views: 1687

Answers (1)

r7r
r7r

Reputation: 1525

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

Upvotes: 2

Related Questions