pnpm/pnpm · error · PnpmError

ALLOW_BUILD_MISSING_PACKAGE

ALLOW_BUILD_MISSING_PACKAGE

Error message

The --allow-build flag is missing a package name. Please specify the package name(s) that are allowed to run installation scripts.

What it means

--allow-build names the packages whose install scripts may run; it is a list flag, not a boolean switch. The guard fires when a bare `--allow-build` (nothing after it) appears in the raw argv while the effective allowBuild list is non-empty because it came from settings, so the flag cannot be silently treated as a blanket approval.

Source

Thrown at pnpm11/installing/commands/src/add.ts:283

      const { alias } = parseWantedDependency(param)
      return alias === 'pnpm' || alias === '@pnpm/exe'
    })) {
      throw new PnpmError('GLOBAL_PNPM_INSTALL', 'Use the "pnpm self-update" command to install or update pnpm')
    }
    return handleGlobalAdd({
      ...opts,
      ...createGlobalPolicyCallbacks(opts),
    }, params, commands ?? {})
  }

  const include = {
    dependencies: opts.production !== false,
    devDependencies: opts.dev !== false,
    optionalDependencies: opts.optional !== false,
  }
  if (opts.allowBuild?.length) {
    if (opts.argv.original.includes('--allow-build')) {
      throw new PnpmError('ALLOW_BUILD_MISSING_PACKAGE', 'The --allow-build flag is missing a package name. Please specify the package name(s) that are allowed to run installation scripts.')
    }
    if (opts.allowBuilds) {
      const disallowedBuilds = Object.entries(opts.allowBuilds)
        .filter(([, value]) => value === false)
        .map(([pkg]) => pkg)
      const overlapDependencies = disallowedBuilds.filter((dep) => opts.allowBuild?.includes(dep))
      if (overlapDependencies.length) {
        throw new PnpmError('OVERRIDING_IGNORED_BUILT_DEPENDENCIES', `The following dependencies are ignored by the root project, but are allowed to be built by the current command: ${overlapDependencies.join(', ')}`, {
          hint: 'If you are sure you want to allow those dependencies to run installation scripts, remove them from the allowBuilds list (or change their value to true).',
        })
      }
    }
    const allowBuilds: Record<string, boolean> = {}
    for (const pkg of opts.allowBuild) {
      allowBuilds[pkg] = true
    }
    if (opts.rootProjectManifestDir) {
      opts.rootProjectManifest = opts.rootProjectManifest ?? {}

View on GitHub (pinned to 5b11d3a15b)

Solutions

  1. Name the packages: `pnpm add <pkg> --allow-build esbuild --allow-build sharp`
  2. Or drop the flag and configure the allow list persistently in pnpm-workspace.yaml (onlyBuiltDependencies / allowBuilds entries)
  3. Use `pnpm approve-builds` interactively after install to grant script permissions

Example fix

# before
pnpm add foo --allow-build

# after
pnpm add foo --allow-build esbuild sharp
Defensive patterns

Strategy: validation

Validate before calling

const raw = process.argv
const i = raw.indexOf('--allow-build')
const next = i !== -1 ? raw[i + 1] : undefined
if (i !== -1 && (next == null || next.startsWith('-'))) {
  console.error('--allow-build needs package names after it')
  process.exit(1)
}

Prevention

When it happens

Trigger: Running `pnpm add <pkg> --allow-build` with no package names after the flag while pnpm-workspace.yaml or config supplies a non-empty allowBuild list.

Common situations: Assuming --allow-build behaves like a boolean strict flag; shell completion inserting the flag without arguments; commands copied from docs that omitted the names.

Related errors


AI-assisted analysis of pnpm/pnpm@5b11d3a15b (2026-08-16). Data as JSON: /api/errors/b78d71a2818577b3. Report an issue: GitHub.