nodejs/node · warning · Error

User cancelled operation

Error message

User cancelled operation

What it means

Thrown by TrustCommand.confirmOperation when the `yes` config resolves to exactly `false`, i.e. the user explicitly passed `--no-yes` (or `--yes=false`). This is the non-interactive hard-decline path: rather than prompting, it aborts immediately. It is distinct from the interactive 'typed n' case (also 'User cancelled operation' but at line 165).

Source

Thrown at deps/npm/lib/trust-cmd.js:156

        }
        if (urlLines.length > 0) {
          output.standard()
          output.standard(urlLines.join('\n'), { [META]: true, redact: false })
        }
      }
      if (pad) {
        output.standard()
      }
    }
  }

  async confirmOperation (yes) {
    // Ask for confirmation unless --yes flag is set
    if (yes === true) {
      return
    }
    if (yes === false) {
      throw new Error('User cancelled operation')
    }
    const confirm = await input.read(
      () => _read({ prompt: 'Do you want to proceed? (y/N) ', default: 'n' })
    )
    const normalized = confirm.toLowerCase()
    if (['y', 'yes'].includes(normalized)) {
      return
    }
    throw new Error('User cancelled operation')
  }

  getFrontendUrl ({ pkgName }) {
    if (this.registryIsDefault) {
      return new URL(`/package/${pkgName}`, NPM_FRONTEND).toString()
    }
    return null
  }

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Pass `--yes` (or `-y`) to auto-confirm, or omit `--no-yes` to get the interactive prompt.
  2. Use `--dry-run` to preview without confirming if you only wanted to inspect.
  3. Remove `yes=false` from .npmrc / environment if it was unintended.

Example fix

// before
npm trust gitlab --file .gitlab-ci.yml --project g/p --allow-publish --no-yes
// after
npm trust gitlab --file .gitlab-ci.yml --project g/p --allow-publish --yes
Defensive patterns

Strategy: validation

Validate before calling

if (config.get('yes') === false) {
  throw new Error('--no-yes blocks confirmation; pass --yes or omit --no-yes')
}

Type guard

const isExplicitNoYes = (cfg) => cfg.get('yes') === false

Try / catch

try {
  await createConfigCommand(...)
} catch (err) {
  if (err.message === 'User cancelled operation' && yesFlag === false) {
    // treat as intentional abort; do not retry
  } else { throw err }
}

Prevention

When it happens

Trigger: Running `npm trust gitlab ... --no-yes`, or having `yes=false` in config/env, against a create/revoke flow that calls confirmOperation. The check `if (yes === false)` short-circuits before the prompt.

Common situations: Automation that deliberately sets --no-yes to forbid mutations; a wrapper script that injects --no-yes; conflicting CI config setting npm_config_yes=false.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/4d25d9a9157e3d9d. Report an issue: GitHub.