External Publication
Visit Post

Gotcha: Yarn may need an empty NPM_TOKEN set to run

Jamie Tanna May 5, 2026
Source

Earlier today I was working with a Yarn codebase for the first time on one of my machines, and I hit an awkward error I'd not seen before:

% yarn install
yarn install v1.22.22
error Error: Failed to replace env in config: ${NPM_TOKEN}
    at /usr/lib/node_modules/yarn/lib/util/env-replace.js:19:13
    at String.replace (<anonymous>)
    at envReplace (/usr/lib/node_modules/yarn/lib/util/env-replace.js:14:16)
    at NpmRegistry.normalizeConfig (/usr/lib/node_modules/yarn/lib/registries/npm-registry.js:423:69)
    at /usr/lib/node_modules/yarn/lib/registries/npm-registry.js:455:36
    at Generator.next (<anonymous>)
    at step (/usr/lib/node_modules/yarn/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /usr/lib/node_modules/yarn/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

A quick search online showed that this is a long-standing issue and can be fixed by exporting an empty NPM_TOKEN environment variable:

% export NPM_TOKEN=
% yarn install
yarn install v1.22.22
...
success Saved lockfile.
Done in 13.89s.

Discussion in the ATmosphere

Loading comments...