[[Node.js FAQs]] Fixing the mysterious `registry.nlark.com` 404 in your Node project

Fixing the mysterious registry.nlark.com 404 in your Node project

The Error

1
2
npm ERR! network request to https://registry.nlark.com/dom-to-image/download/dom-to-image-2.6.0.tgz failed
npm ERR! code ENOTFOUND

You’ll usually see this when running npm install (or yarn install) on a project last updated a few years ago.

What’s going on?

  • registry.nlark.com no longer exists.
    The domain once pointed to Yuque’s private npm mirror (an Alibaba side-project). DNS now returns NXDOMAIN—meaning “this name is nowhere to be found”.
  • Old lockfiles hard-code the mirror.
    Anything published between late 2019 – 2021 could have registry.nlark.com baked into package-lock.json or yarn.lock.

The two-minute fix

  1. Delete stale lockfiles

    1
    rm -f package-lock.json yarn.lock
  2. Re-install with the default registry

    1
    npm install        # or:  yarn install

    Fresh lockfiles will point at the official registry ( https://registry.npmjs.org/ ) and you’re done.

Prefer not to lose lockfile history?

Search-and-replace the dead mirror with its modern twin, registry.npmmirror.com (a CDN-backed clone run by Tsinghua & Alibaba).

1
2
3
4
5
# macOS / Linux
sed -i '' 's#registry\.nlark\.com#registry.npmmirror.com#g' package-lock.json yarn.lock
# Windows (PowerShell)
(Get-Content package-lock.json) -replace 'registry\.nlark\.com','registry.npmmirror.com' | Set-Content package-lock.json
(Get-Content yarn.lock) -replace 'registry\.nlark\.com','registry.npmmirror.com' | Set-Content yarn.lock

Then run npm install again.