Key Takeaways
- You change your npm registry in
.npmrc, but environment variables and flags can quietly override it. - Yarn Berry ignores
.npmrc, and current pnpm won’t expand a token variable in a committed.npmrc. EINTEGRITYafter a switch is a checksum mismatch, so trace the failing package before you refresh the lockfile.- Verify the effective registry, review lockfile changes on a branch, and let CI keep watch afterward.
Changing your npm registry looks like a one-line job, and in a sense it is. You add a URL to .npmrc, run an install, and move on. Then CI goes red on a branch nobody touched, a teammate’s laptop is still pulling from registry.npmjs.org, and the first clean install throws an integrity error that looks an awful lot like tampering.
Usually, none of that means the switch failed. A package manager did exactly what its config told it to, and either the config it read wasn’t the one you edited or the lockfile was still holding on to the old registry. I’ve seen enough teams point their builds at SecureChain to know the registry line is rarely the problem. The trouble lives in everything around it.
This walkthrough covers npm, pnpm, Yarn Classic, and Yarn Berry, roughly in the order things tend to break.
How to change your npm registry in .npmrc
For npm and Yarn Classic, setup really is one small file in the project root. Create or edit .npmrc next to your package.json. This is the manual setup for SecureChain, the TuxCare registry that serves open source packages rebuilt from verified source and patched against known CVEs, with the token read from an environment variable instead of pasted in:
registry=https://artifacts.tuxcare.com/npm/
//artifacts.tuxcare.com/npm/:_authToken=${TUXCARE_TOKEN}
The first line makes SecureChain the default registry for every package that doesn’t have its own scope registry configured somewhere else. Dependencies declared as Git URLs or tarball links skip the registry altogether. The second attaches your token to that host and path. npm requires credentials to be scoped to a registry URL this way, so your token doesn’t get sent to some unrelated registry by accident.
Switching the registry doesn’t require touching package.json. Names and version ranges stay as they are, and packages SecureChain doesn’t rebuild still resolve through the same endpoint from the public upstream. Pinning patched builds is a separate step, and I’ll get to it below. TuxCare’s CLI sets the registry up a little differently, and that’s covered below too.
Use the raw token with _authToken. If you go digging through old blog posts, you’ll find _auth, which expects a Base64-encoded username:password pair. Hand it a raw token instead and you’ll get a wall of 403s, which is a miserable thing to debug late on a Friday.
pnpm wants the registry token somewhere else
pnpm reads the same .npmrc, so the registry= line works exactly as above. The token line is where it gets interesting.
Starting with versions 10.34.2 and 11.5.3, pnpm stopped expanding environment variables in the project and workspace .npmrc for registry URLs, URL-scoped keys, and credentials. The reason is a good one. A committed .npmrc comes from whoever controls the repository, and expanding ${SOMETHING} there let a malicious repo ship your CI token off to a registry it controlled. Variables still expand in your user-level ~/.npmrc, the global config, command-line options, and environment config.
So on a current pnpm, ${TUXCARE_TOKEN} in the committed file won’t resolve by default. pnpm prints a warning that it ignored a project-level auth setting. Unless a token is already sitting in your user-level config, it carries on without one and the registry turns the request down. If a pipeline that was green last month started failing authentication right after a routine pnpm bump, start here. Keep the registry= line in the project file, where a literal URL is fine, and write the token to user-level config instead, which is the route pnpm’s own docs recommend:
pnpm config set "//artifacts.tuxcare.com/npm/:_authToken" "$TUXCARE_TOKEN"
pnpm config set writes to your user-level config by default, never to the project file, so the token stays out of the repo. In CI, run that as a step before the install. It does store the token on disk, so clean it up on a runner that outlives the job.
Why npm is still using the wrong registry
I call this one registry shadowing. A config setting you didn’t edit decides which registry an install actually hits. Your .npmrc looks right, the diff looks right, and the install goes somewhere else anyway.
It happens because npm doesn’t read one config file. It reads four of them: the project .npmrc, your user-level ~/.npmrc, a global file under the npm prefix, and one that ships with npm itself. Environment variables and command-line flags take precedence over all of them. Among the files, project beats user and user beats global, and a normal install won’t mention the ones that lost. In practice, registry problems tend to come from a handful of places.
The first is the setup that only exists on one laptop. Someone runs npm config set registry <url>, which writes to their user-level config by default rather than to the project. Everything works locally, nothing gets committed, and CI has never heard of SecureChain. If you want the CLI route, npm config set registry <url> --location=project writes to the project file instead.
The second is CI itself. An NPM_CONFIG_REGISTRY variable set in a shared pipeline template wins over the registry in every .npmrc in the repo, and whoever set it may have moved teams two years ago.
The third is global installs. npm ignores the project .npmrc when you install with -g, so a CLI tool installed globally in your Dockerfile can come straight from the public registry while the app sitting next to it comes from SecureChain.
The fourth is scope lines. A line like @company:registry=https://another-registry.example.com/ sends everything under that scope to a different registry, whatever the default says. That’s the right setup for your internal packages. It’s also easy to forget about, and an old scope line pointing somewhere unexpected will quietly route a slice of your tree around SecureChain. Before you call the switch done, search every .npmrc you can reach for :registry= and make sure each hit is there on purpose.
Yarn Berry does not read your .npmrc
If you’re on Yarn 2 or newer, none of the .npmrc rules above apply to you. Yarn Berry ignores .npmrc completely and reads .yarnrc.yml instead. This often catches teams that migrated from Yarn Classic without moving their registry settings over. The .npmrc still sitting in the repo looks authoritative and does nothing at all.
The easiest fix is to let tuxcarectl init write the file, since it detects Berry and writes .yarnrc.yml instead of .npmrc. If you’re editing it by hand, three Yarn settings do the work. npmRegistryServer sets the registry, npmAuthToken holds the token, and npmAlwaysAuth tells Yarn to send that token on every request instead of waiting to be asked, which matters for any registry that won’t answer anonymous requests. Berry also understands the ${TUXCARE_TOKEN} syntax, so the token can stay out of the file. With more than one registry in play, set the token under npmRegistries for the TuxCare host instead.
Run yarn --version if you’re not sure which Yarn you have. Anything 2.x or higher is Berry.
Keep the registry token out of Git
The npm example reads the token from an environment variable instead of hardcoding it, and Yarn Berry can do the same. That lets you commit the config file without exposing the credential, which matters because a registry setting that only lives on laptops is exactly how shadowing starts.
Locally, load TUXCARE_TOKEN into your environment from whatever secrets tool you already use rather than pasting it into a dotfile. In CI, store it in the platform’s secret store and expose it only to the steps that install packages.
One npm quirk is worth knowing here. If the variable isn’t defined, npm leaves the placeholder in place as literal text, so it sends the string ${TUXCARE_TOKEN} as your token and the registry turns it down. You don’t get a friendly “variable not set” message. If a command works on your machine and fails authentication in CI, check that the secret is actually reaching the install step before you check anything else.
Why EINTEGRITY shows up after you change registries
This is the one that looks scary. You switch registries, run npm ci, and get EINTEGRITY.
If the project was installed against the public registry before, each registry entry in your lockfile carries an integrity hash for the public tarball. SecureChain serves packages it rebuilt from source, and a rebuilt tarball generally doesn’t have the same bytes as the public one, so for those packages the hashes no longer match. npm compares them, sees the mismatch, and stops.
Expected isn’t the same as proven, though. An integrity failure tells you the bytes changed. It doesn’t tell you who changed them. So before you accept new hashes, run npm config get registry and make sure it returns the SecureChain URL. If it does, you’ve ruled out a misconfigured default registry, and the rebuild becomes the likely explanation. Your lockfile just did its job. If it returns something you didn’t expect, stop there and work out why first.
That check only covers the default registry, and it says nothing about the bytes. A scoped package may be coming from somewhere else entirely, so look at where the package named in the error was actually fetched from.
There’s a subtle npm detail here too. By default, npm treats registry.npmjs.org in a lockfile’s resolved field as a stand-in for whatever registry is currently configured. That’s why you get an integrity error rather than a silent download from the public registry. npm fetches from the configured registry and then checks the result against the old hash.
Once you’ve confirmed the registry, the cleanest route is to let tuxcarectl harden handle the lockfile for you (more on that below). By hand, on the manual setup above, the fix is to delete node_modules and package-lock.json, run a fresh install, and commit the new lockfile, which now records SecureChain URLs and checksums. pnpm and Yarn keep integrity data in their own lockfile formats, so expect a similar checksum failure there, worded differently, and regenerate through that package manager rather than editing hashes by hand.
Update the lockfile on a branch and review the diff
The quick-start version usually skips this part. Deleting a lockfile doesn’t just swap URLs and hashes. It re-resolves every semver range in your tree, so a fresh install can also move you to newer versions inside ranges you’ve already declared. Usually that’s fine. Every so often it’s a minor release with a behavior change three levels down, which is exactly the kind of surprise a supply chain project shouldn’t introduce.
So do it on a branch. Read the lockfile diff before you merge, and look for two kinds of change: the registry and hash updates you asked for, and any version bumps you didn’t intend. In package-lock.json, a rebuilt package at the same version changes resolved and integrity and leaves version alone. Where version itself moved, a -tuxcare.N suffix is a patched build pinned on purpose. Anything else is an upstream bump and deserves a second look. Then prove the new lockfile installs cleanly in a fresh checkout, the way CI and your teammates will install it:
npm ci
pnpm install --frozen-lockfile
yarn install --frozen-lockfile # Yarn Classic
yarn install --immutable # Yarn Berry
Run the test suite on that install. It keeps the registry switch from getting blamed for an unrelated upgrade.
Prove which registry npm is using before you merge
I don’t consider a registry switch done until I’ve checked the package manager’s effective configuration. The contents of a file only tell you what you meant to happen.
On the manual setup, npm config get registry should return https://artifacts.tuxcare.com/npm/. If the CLI configured the project, expect the same host with /npm-upstream/ on the end. pnpm config get registry works the same way. On Yarn Classic it’s yarn config get registry, and on Berry it’s yarn config get npmRegistryServer. If you get the public URL back, either your config never loaded or something is overriding it. For npm, npm config list shows each setting and where it came from, which usually settles it in a few seconds.
| Package manager | Registry config file | Token | Check the default registry |
|---|---|---|---|
| npm | .npmrc |
.npmrc, as _authToken |
npm config get registry |
| pnpm | .npmrc |
User-level config, via pnpm config set |
pnpm config get registry |
| Yarn Classic (1.x) | .npmrc |
.npmrc, as _authToken |
yarn config get registry |
| Yarn Berry (2 and newer) | .yarnrc.yml |
.yarnrc.yml, as npmAuthToken |
yarn config get npmRegistryServer |
npm ping should print PONG, which tells you the registry is reachable. npm whoami should succeed too, and that one confirms the token was accepted. Don’t be surprised if it prints a service identity rather than your name. That’s normal here.
Then open the new lockfile and search for the TuxCare host. The resolved fields tell you where future installs will fetch from, and npm list tells you what’s actually installed right now. Patched builds are easy to spot in that output, because their versions end in -tuxcare.N. The suffix is only a label, so check the resolved URL beside it too.
Last, put the check somewhere people can’t forget it. On a hardened project, tuxcarectl check reads what’s installed and fails the build if it has drifted, for example when a patched build your subscription covers isn’t the one in use, or when the lockfile has slipped back to the public registry for a package that was moved. That turns “did we actually switch?” from something a person has to remember into a status check on every pull request.
Let the SecureChain CLI do the tedious part
All of the above is worth understanding, but you don’t have to do it by hand. The SecureChain CLI, tuxcarectl, detects whether you’re on npm, pnpm, Yarn, or Bun. (It also answers to its earlier name, securechain.) tuxcarectl init writes the registry config your package manager expects, .npmrc or .yarnrc.yml for Yarn 2 and newer. It writes no credential. On a developer machine, tuxcarectl registry login puts that in your user-level config, and tuxcarectl registry env supplies it to a CI job. tuxcarectl harden pins the patched builds, refreshes the lockfile, reinstalls, and verifies that the installed tree really changed. If that verification fails, it puts your files back. Run tuxcarectl harden --dry-run if you’d like to see the plan before anything moves.
The CLI doesn’t configure the registry the way the manual setup does. The TuxCare registry has two npm paths on the same host. /npm/ serves the TuxCare builds, and /npm-upstream/ serves the public packages byte for byte. Current versions of the CLI point your project at /npm-upstream/, and harden writes the /npm/ URL and hash into the lockfile entry of each build it pins. Nothing your existing lockfile installs changes underneath it, which avoids the integrity mismatch described earlier.
Pinning matters more than it might seem. A lot of what needs patching sits in transitive dependencies you never named in package.json, and the standard way to force a specific build of one of those is an override in npm and pnpm or a resolution in Yarn. The CLI writes those for you across the whole resolved tree. Overrides and resolutions live in your project manifest, usually package.json, or pnpm-workspace.yaml on newer pnpm. Read that part of the diff as carefully as the lockfile. Later, tuxcarectl update moves those pins to newer builds of the same version, which npm update won’t do.
I still review the diff afterward. Old habits.
What about Artifactory, Nexus, and GitHub Packages?
If your organization routes every install through a repository manager, TuxCare says SecureChain can be configured as an upstream source for Artifactory, Nexus, and GitHub Packages. Project config still matters, because it’s what points each package manager at the repository manager in the first place. But the question of which artifact actually gets served moves up a level, into upstream order, caching, and repository policy. That setup has its own traps, and it deserves a write-up of its own.
The config is the easy part
Changing the registry takes a minute. Making sure every laptop, pipeline, and Docker build actually honors it is the real work. Once it does, getting a patched build into production becomes a routine pull request with a check on it, and you stop having to wonder whether the fix really landed.
Frequently Asked Questions
How do I change the npm registry for a single project?
Add a registry= line to a .npmrc file in the project root, next to package.json, and commit it. You can also run npm config set registry <url> --location=project. Project config takes priority over your user and global files, although environment variables and command-line flags can still override it.
How do I check which registry npm is actually using?
Run npm config get registry from the project root. It prints the default registry npm will use once every config file and environment variable has been applied. If the answer surprises you, npm config list shows which source each setting came from.
Does Yarn read .npmrc?
Yarn Classic (1.x) does. Yarn 2 and newer ignore .npmrc and read registry and authentication settings from .yarnrc.yml, using npmRegistryServer, npmAuthToken, and, for registries that require a token on every request, npmAlwaysAuth.
Why doesn’t pnpm pick up the token in my .npmrc?
Since versions 10.34.2 and 11.5.3, pnpm by default no longer expands environment variables in a project or workspace .npmrc for registry URLs, URL-scoped keys, or credentials, because a malicious repository could use that to steal tokens. Put the token in user-level config with pnpm config set instead.
Why do I get EINTEGRITY after switching npm registries?
EINTEGRITY means a downloaded tarball didn’t match the hash in your lockfile. After a registry switch, a likely cause is a lockfile that still holds hashes for the public tarballs while the new registry serves rebuilt packages with different bytes. Confirm which registry the failing package came from before you refresh anything. Projects set up with the TuxCare CLI avoid the mismatch.
Do I need to change package names or versions in package.json?
Not to switch registries. Names and version ranges stay the same. Pinning patched builds is a separate step. The SecureChain CLI pins them through overrides or resolutions, which live in your project manifest or, on newer pnpm, in pnpm-workspace.yaml, so review those changes alongside the lockfile.
What does ETARGET mean for a patched TuxCare version?
In npm, ETARGET means no matching version was found. Patched TuxCare builds carry versions ending in -tuxcare.N, and on the TuxCare registry they’re served from the /npm/ path. If a tool asks for one from the public registry or from /npm-upstream/, it stops with ETARGET.
What happens when a package I depend on reaches end of life?
For packages SecureChain maintains, Endless Lifecycle Support (ELS) continues security coverage after end of life. New patched builds land on the same registry, and tuxcarectl update moves your project to them.
