Hacker News new | ask | show | jobs
Why doesn't NPM first check if the package is already installed locally?
5 points by blrboy 2274 days ago
And then a symlink or something of the sort could be created - or perhaps even a copy of the module in question. Why isn't this the way npm works?

If I initialize 10 different projects, and they all need React, I'd presumably do npm install react 10 distinct times. Which is fine, since each app is standalone - but why "waste" bandwidth by making separate requests for each one?

2 comments

Not sure about NPM, but Yarn, even v1 without PNP caches all packages and simply copies the package from the local cache into your `node_modules`.

It doesn't do symlinks (PNP mode does) because this doesn't always work well and it definitely doesn't work well on Windows.

See: https://classic.yarnpkg.com/en/docs/cli/cache/

Yarn’s PNP mode does this.