yarnpkg/yarn · error · MessageError

nonInteractiveNoToken

Error message

nonInteractiveNoToken

What it means

During login, yarn first checks the YARN_AUTH_TOKEN / NPM_AUTH_TOKEN env vars (login.js:71-74); if absent and the process is non-interactive (flags.nonInteractive or config.nonInteractive, login.js:78) it cannot prompt for credentials and throws nonInteractiveNoToken.

Source

Thrown at src/cli/commands/login.js:75

    config.registries.npm.setToken(auth);
    return function revoke(): Promise<void> {
      reporter.info(reporter.lang('notRevokingConfigToken'));
      return Promise.resolve();
    };
  }

  const env = process.env.YARN_AUTH_TOKEN || process.env.NPM_AUTH_TOKEN;
  if (env) {
    config.registries.npm.setToken(`Bearer ${env}`);
    return function revoke(): Promise<void> {
      reporter.info(reporter.lang('notRevokingEnvToken'));
      return Promise.resolve();
    };
  }

  // make sure we're not running in non-interactive mode before asking for login
  if (flags.nonInteractive || config.nonInteractive) {
    throw new MessageError(reporter.lang('nonInteractiveNoToken'));
  }

  //
  const creds = await getCredentials(config, reporter);
  if (!creds) {
    reporter.warn(reporter.lang('loginAsPublic'));
    return function revoke(): Promise<void> {
      reporter.info(reporter.lang('noTokenToRevoke'));
      return Promise.resolve();
    };
  }

  const {username, email} = creds;
  const password = await reporter.question(reporter.lang('npmPassword'), {
    password: true,
    required: true,
  });

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Export an auth token: `export NPM_AUTH_TOKEN=<token>` (or YARN_AUTH_TOKEN) in the environment.
  2. Configure an .npmrc with `//registry.npmjs.org/:_authToken=<token>` for the CI runner.
  3. Drop --nonInteractive and run in an interactive shell so the prompt can collect credentials.
  4. For publish in CI prefer a pre-provisioned token over `yarn login`.

Example fix

# before
$ yarn login --nonInteractive   # throws nonInteractiveNoToken
# after (CI)
$ export NPM_AUTH_TOKEN=npm_xxx
$ yarn login --nonInteractive
Defensive patterns

Strategy: validation

Validate before calling

function ensurePublishToken() {
  const token = process.env.YARN_AUTH_TOKEN || process.env.NPM_AUTH_TOKEN;
  const interactive = process.stdout.isTTY;
  if (!token && !interactive) {
    throw new Error('No auth token and no TTY: set NPM_AUTH_TOKEN or run interactively.');
  }
}

Try / catch

try {
  await runYarn(['login', '--nonInteractive']);
} catch (e) {
  if (/nonInteractiveNoToken/.test(e.message)) {
    console.error('CI auth missing: export NPM_AUTH_TOKEN before publishing.');
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `yarn login --nonInteractive` in CI without an auth token env var; any login attempt in a detached/TTY-less environment where config.nonInteractive auto-activates and no token env var is present.

Common situations: CI pipelines (GitHub Actions, Jenkins) that forgot to expose the npm token; Docker builds with no TTY; scripts that pass --nonInteractive but rely on interactive prompt.

Related errors


AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13). Data as JSON: /api/errors/119bbf7f5db0284b. Report an issue: GitHub.