Gotcha: Yarn may need an empty NPM_TOKEN set to run

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.

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #javascript.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.