News for hackers. Stuff that matters.
Re:Cleaning house in Nx monorepo, how i removed unused deps ... by zdragnar on Sunday September 28, 2025 @10:30PM (#45409880)
1- I want my dependencies to define a range for the libraries that they work with, so we don't have 20 different versions of some common library because our dependencies are hyper specific

2- I want every install of my project- be it on a dev machine or deploy machine- to have the exact same versions of dependencies, including transitive ones. I don't want to deal with bugs caused by surprise version changes

3- if I upgrade a dependency or remove it, I want the transitive dependencies managed automatically. I don't want orphaned transitive dependencies. In fact, I don't even want to think about them at all other than know that they work and aren't adding bloat or security risks.

You need a package manager with more than a passing thought for handling lock files. For the longest time, npm wasn't it. I'd argue that it still isn't, because "npm install" should NOT be the command used for both "set up a project for the first time" and "add a new package". In the first case, I want a reproducible, deterministic result of a known state. In the second case, I want to modify the dependency graph, producing a new state.

Re:Cleaning house in Nx monorepo, how i removed unused deps ... by montroser on Sunday September 28, 2025 @11:20PM (#45410058)
> I want a reproducible, deterministic result of a known state

Yes, that's `npm ci`.

With a fresh `npm install` you get the latest packages that satisfy dependencies in the ranges spec'd in package.json. That's basically a crap shoot because even if you specifically pin the versions of all your dependencies, chances are that at least some of your dependencies did not have the good sense to do the same for their dependencies. This is the path to hell.

With a fresh `npm ci` on the other hand, you get back exactly to the known state specified in package-lock.json, where everything is pinned, all the way down. This is the path to happiness.

Re:Cleaning house in Nx monorepo, how i removed unused deps ... by rectang on Sunday September 28, 2025 @11:47PM (#45410162)
Does anybody disable `npm install`? For yourself? For a team?
Re:Cleaning house in Nx monorepo, how i removed unused deps ... by zdragnar on Monday September 29, 2025 @12:43AM (#45410396)
The official tutorial at https://nodejs.org/en/learn/getting-started/an-introduction-... says to use `npm install` and makes no mention of `npm ci` at all. Further, the name of the command (though not the clean-install alias) shows that it was tacked on top of a fundamentally broken base.

> That's basically a crap shoot because even if you specifically pin the versions of all your dependencies, chances are that at least some of your dependencies did not have the good sense to do the same for their dependencies.

As I mentioned in my first comment, I don't really want my dependencies to pin their dependencies. I want them to specify a range they work with to minimize the number of redundant copies of common transitive dependencies.

Re:Cleaning house in Nx monorepo, how i removed unused deps ... by chrisweekly on Monday September 29, 2025 @08:32AM (#45412909)
PSA: pnpm is fundamentally superior to npm or yarn; used properly, it provides reproducible / deterministic builds, with efficient control of the dependency graph.
Re:Cleaning house in Nx monorepo, how i removed unused deps ... by chuckadams on Monday September 29, 2025 @11:31AM (#45415072)
> used properly

That phrase is frequently way more load-bearing than it should be. Is pnpm's default behavior the correct one? (yarn user here, but open to switching)

Re:Cleaning house in Nx monorepo, how i removed unused deps ... by chrisweekly on Monday September 29, 2025 @11:55AM (#45415349)
Yes.

No tool can prevent all footguns, but standard / idiomatic / out-of-the-box pnpm usage beats even expert use of npm or yarn. It's different, and better.