Nathan
Nathan

Reputation: 360

Why does each React app require a seperate node_module file?

I've noticed that even a simple webpage that shows "hello world" takes up over 600 MBs on my laptop, the node_modules folder alone is like 590MBs for me. Also, when I run npx create-react-app it takes couple minutes for everything to get ready and I'm assuming this is because for each React app npm generates a new node_modules?

Just out of curiosity, why is this the case? Why can't React apps just rely on a global dependency so there's only one node_modules for all apps (and if there is a way to do this, please let me know)?

Upvotes: 0

Views: 46

Answers (1)

Xavier Malparty
Xavier Malparty

Reputation: 66

This is the current architecture of an NPM project. Probably also a legacy.

can't React apps just rely on a global dependency?

Well, actually they can. This is what PNPM is doing: https://pnpm.io/

Maybe a future version of NPM would also integrate that, but I do not expect it to come so quickly (when you have a whole ecosystem around your current architecture, the inertia to change is quite high).

Upvotes: 1

Related Questions