DEV Community

Cover image for Your Workspace Package's `.npmrc` Does Nothing. The Root File Decides Everything
AheadKit
AheadKit

Posted on

Your Workspace Package's `.npmrc` Does Nothing. The Root File Decides Everything

Four installs. Four hooks ran. The warning showed up twice, and both times in the one place where it could do nothing at all.

cryptostrapon asked this one in the comments on my last npm piece, and it is the sharpest edge in the whole series so far. He runs a workspaces monorepo where three files disagree. The root file says hooks may run. The package's own file, inside packages/a, says they may not. His user file says they may not too. From a root install, npm printed that it was ignoring the workspace config at packages/a/.npmrc, and the package's install hook ran anyway. His point was not that the root wins. We already knew the root wins. His point was that a check inside the package reads green and tells you nothing, because the root file plus env and flags are what decide, and the package file is not even part of the conversation.

I rebuilt his shape and ran it on npm 10.9.4 with Node v24.22.1. The monorepo is one root package.json with a packages/* workspace, one package called pkg-a, and three config files that disagree about one setting: the user file and the package file switch install hooks off, the root file switches them on.

user file (~/.npmrc):             ignore-scripts=true
root file (./.npmrc):             ignore-scripts=false
package file (packages/a/.npmrc): ignore-scripts=true
read the one value with:          npm config get ignore-scripts
Enter fullscreen mode Exit fullscreen mode

The package carries one install hook that writes a marker file, HOOK-RAN.txt, with the time it ran. Two runs of every shape, and I kept the raw output for all of it.

Here is the whole run in one table, before I argue about any of it.

Where I stood What I asked What came back Hook ran?
Monorepo root npm config list User value true, marked "overridden by project"; project value false. The package file is not mentioned once, in the plain list or the JSON list. n/a
Monorepo root Read the one value false n/a
Inside packages/a npm config list The "ignoring workspace config" warning, then an error: ENOWORKSPACES, "This command does not support workspaces." No value at all. n/a
Inside packages/a Read the one value Same warning, same error. No value at all. n/a
Monorepo root npm install, run 1 added 1 package in 1s. No warning, no hook output. Marker stamped 00:07:34 UTC. Yes
Monorepo root npm install, run 2 up to date in 2s. No warning, no hook output. Marker restamped 00:07:36 UTC. Yes
Inside packages/a npm install, run 1 Warning printed, then up to date in 1s. Marker stamped 00:07:38 UTC. Yes
Inside packages/a npm install, run 2 Warning printed, then up to date in 1s. Marker stamped 00:07:39 UTC. Yes

Four installs, four markers, and the two runs of each shape agreed every time. The behaviour is steady, and the package file loses everywhere, including in its own folder.

The root check is honest, and it says nothing about your package

Run the check at the root and npm is straight with you. It shows the user value, true, with the note that the project overrides it, and then the project value, false. Ask for the single value and it says false. That is the value the root install will use, and the root install did use it: the hook ran both times.

What the root check never does is mention the package file. I counted. Zero mentions of packages/a in the plain config list, and zero in the JSON dump too. The file exists on disk, it says the opposite of the root file, and the check at the root behaves as if it is not there. That is the correct behaviour for the install, and it is a trap for the reader. A person who opens the package file, sees the hooks-off value, and then runs the check at the root to confirm it will read false and think the check disagrees with the file. It does not disagree. It is answering a different question: what will the root install do. The package file is not part of that answer, and the check gives you no hint that a file with the opposite value is sitting one folder down.

The check inside the package does not return a value

This is the part cryptostrapon was really asking about, and the answer is worse than "it reads green." There is no per-package reading to trust or mistrust. Stand inside packages/a and ask for the config, and npm prints the warning about ignoring the workspace config and then fails outright: ENOWORKSPACES, "This command does not support workspaces." Ask for the single value and you get the same warning and the same error. Two attempts, two errors, zero values returned.

So the check he described, a per-package check that reads green, is not a check npm will even perform in a workspace package. The command refuses. The warning is real and it sits right there in the output, but it sits next to an error, and the error is the actual answer: inside a workspace package, npm does not let you ask what the package's own file says. Anyone who believes they verified the package file by running a check inside the package folder either ran the check somewhere else without noticing, or read the warning as a verdict and stopped there. The warning is not a verdict. It is a note attached to a refusal.

The warning is not a gate

He reported seeing the warning, and I want to be exact about where I saw it, because it did not show up where I expected. Across two root installs, the warning appeared zero times. The output was one line each time, added 1 package in 1s and then up to date in 2s, with nothing about the hook and nothing about the ignored file. The hook ran in silence both times, and the second run is the detail I keep coming back to: npm said the tree was up to date and still ran the hook again, restamping the marker two seconds after the first run. "Up to date" describes the packages. It says nothing about whether their hooks ran, and here the hook ran anyway.

The warning appeared only when I ran commands from inside the package folder, twice out of two per-package installs, and both times the hook ran anyway. So the warning shows up at the moment you are standing in the folder whose file is being ignored, and the install that prints it still obeys the root file. It tells you the file is dead while doing exactly what the file forbids. That is not a gate. A gate stops something. This is a label on a door that is already open, and it only appears after you have walked through it from the other side.

One honest caveat: he saw the warning on the npm version he runs; on 10.9.4 the root install stayed silent. The warning's timing may differ by version, and I did not test his. But the outcome did not differ: on both, the root file decided, the hook ran, and the package file changed nothing. If you are waiting for a warning to tell you a package file is being ignored, you are waiting for a message that may never arrive before the install, and that arrives too late when it does.

What I do with the package file now is simple: I delete it. A file that does nothing but suggest protection is worse than no file at all, because the next person to open it will believe it. If hooks must stay off in a workspace, the setting belongs in the root file, in the environment, or on the command line, the three places the root install actually reads, and I verify it with a plain value read at the root before the install runs. The package folder gets no config file of its own, because a config file there is a note written to a reader who never opens it, in a folder where the check itself refuses to run.


P.S. Everything I write stays free — that part doesn't change. But if this one was worth something to you, you can buy me a coffee ☕ (one-time or monthly, both work). It covers the API credits and hosting behind these experiments — and honestly, it's also the nudge that gets the next one started on the evenings I'd otherwise skip it. — Salam

Buy me a coffee

AheadKit on Gumroad — Beginner-Friendly Books & Packs

Top comments (4)

Collapse
 
sunnatulla_dev profile image
Sunnatulla •

That green per-package check does exist, it just needs --no-workspaces. I rebuilt your three files on npm 10.9.9 and inside packages/a npm config get ignore-scripts --no-workspaces prints true from the package file, while the root install runs the hook. npm install --no-workspaces there does skip it, but leaves a stray package-lock.json in the package.

Collapse
 
aheadkit profile image
AheadKit •

--no-workspaces is the bit the piece missed, fair catch — a per-package check that actually reads the package file is a different thing from one that just reads the root and calls it a day. The stray lockfile though, is that just clutter to clean up, or does it bite anything downstream when the root install runs again?

Collapse
 
sunnatulla_dev profile image
Sunnatulla •

For the root it's just clutter. I pinned ms 2.1.2 in the package's own lock while the root lock had 2.1.3, and root npm ci installed 2.1.3. Even plain npm ci inside packages/a walked up to the root and used its lock.

It bites when the package gets installed on its own: npm ci --no-workspaces there, or a Dockerfile that copies only that folder, both installed 2.1.2. So a build can ship a different tree than the one CI tested. I'd delete it and add packages/*/package-lock.json to .gitignore.

Thread Thread
 
aheadkit profile image
AheadKit •

the Dockerfile case is the one that would've bitten me — same repo, different tree than CI tested, and nothing looks wrong until it ships. do you delete the stray lock in your repos now, or keep it around for the standalone-install case?