nodejs/node · error · Error

Cannot use --no-workspaces and --workspace at the same time

Error message

Cannot use --no-workspaces and --workspace at the same time

What it means

In the base command constructor, npm validates that you have not combined --no-workspaces (disable workspace expansion) with one or more --workspace/-w selectors. These are contradictory intents, so the command refuses to run rather than guess which wins.

Source

Thrown at deps/npm/lib/base-cmd.js:150

    const helpName = parentName ? parentName.split(' ')[0] : name
    fullUsage.push(`Run "npm help ${helpName}" for more info`)

    return fullUsage.join('\n')
  }

  constructor (npm) {
    this.npm = npm
    this.commandArgs = null
    this.parentName = null

    const { config } = this

    if (!this.constructor.skipConfigValidation) {
      config.validate()
    }

    if (config.get('workspaces') === false && config.get('workspace').length) {
      throw new Error('Cannot use --no-workspaces and --workspace at the same time')
    }
  }

  get config () {
    // Return command-specific config if it exists, otherwise use npm's config
    return this.npm.config
  }

  get name () {
    return this.constructor.name
  }

  get description () {
    return this.constructor.description
  }

  get params () {
    return this.constructor.params

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Drop --no-workspaces when you actually want to target the listed workspace(s)
  2. Drop all --workspace/-w flags if your intent is to disable workspace expansion entirely
  3. Audit .npmrc and the nearest package.json 'workspaces' field plus npm_config_workspace env for stale values

Example fix

# before
npm run test --workspace=pkg-a --no-workspaces

# after
npm run test --workspace=pkg-a
Defensive patterns

Strategy: validation

Validate before calling

const cfg = npm.config
const conflict = cfg.get('workspaces') === false && cfg.get('workspace').length > 0
if (conflict) {
  throw new Error('Refusing to run: --no-workspaces conflicts with --workspace selectors')
}

Type guard

function workspaceFlagsConflict(cfg) {
  return cfg.get('workspaces') === false && Array.isArray(cfg.get('workspace')) && cfg.get('workspace').length > 0
}

Prevention

When it happens

Trigger: Passing both flags on one invocation, e.g. `npm run build --workspace=pkg-a --no-workspaces`. Also triggered when an .npmrc or package.json 'workspace' config is set and the CLI adds --no-workspaces (or vice-versa).

Common situations: CI matrix scripts that append -w flags to a base command which itself ships --no-workspaces; shell aliases; inheriting workspace config from a monorepo root while debugging a single package with --no-workspaces.

Related errors


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