parcel-bundler/parcel · error · ThrowableDiagnostic

Targets option is an empty array

Error message

Targets option is an empty array

What it means

Thrown by TargetRequest.resolve() when this.options.targets is an empty array []. Passing an empty targets array is explicitly invalid — it would produce zero build targets. Parcel catches this early with a clear message rather than silently building nothing.

Source

Thrown at packages/core/core/src/requests/TargetRequest.js:215

    this.targetInfo = new Map();
  }

  async resolve(
    rootDir: FilePath,
    exclusiveTarget?: string,
  ): Promise<Array<Target>> {
    let optionTargets = this.options.targets;
    if (exclusiveTarget != null && optionTargets == null) {
      optionTargets = [exclusiveTarget];
    }

    let packageTargets: Map<string, Target | null> =
      await this.resolvePackageTargets(rootDir, exclusiveTarget);
    let targets: Array<Target>;
    if (optionTargets) {
      if (Array.isArray(optionTargets)) {
        if (optionTargets.length === 0) {
          throw new ThrowableDiagnostic({
            diagnostic: {
              message: `Targets option is an empty array`,
              origin: '@parcel/core',
            },
          });
        }

        // Only build the intersection of the exclusive target and option targets.
        if (exclusiveTarget != null) {
          optionTargets = optionTargets.filter(
            target => target === exclusiveTarget,
          );
        }

        // If an array of strings is passed, it's a filter on the resolved package
        // targets. Load them, and find the matching targets.
        targets = optionTargets
          .map(target => {

View on GitHub (pinned to 59484858a1)

Solutions

  1. If you want all targets, pass targets: undefined or omit the option entirely.
  2. If filtering targets programmatically, guard against the empty result and either omit the option or throw your own clearer error.
  3. Ensure at least one target name is present when passing an array.

Example fix

// before
const bundler = new Parcel({
  entries: 'src/index.html',
  targets: activeTargets, // activeTargets happens to be []
});

// after
const bundler = new Parcel({
  entries: 'src/index.html',
  targets: activeTargets.length > 0 ? activeTargets : undefined,
});
Defensive patterns

Strategy: validation

Validate before calling

function validateTargetsOption(targets) {
  if (Array.isArray(targets) && targets.length === 0) {
    throw new Error('targets option cannot be an empty array; pass undefined to use all targets.');
  }
}

Type guard

function isValidTargetsOption(targets) {
  return targets == null
    || (Array.isArray(targets) && targets.length > 0)
    || (typeof targets === 'object' && !Array.isArray(targets));
}

Prevention

When it happens

Trigger: At the top of resolve(), after optionTargets = this.options.targets. If optionTargets is truthy, Array.isArray(optionTargets) is true, and optionTargets.length === 0, the error fires before any target resolution.

Common situations: Programmatically constructing Parcel options and passing targets: [] by mistake (e.g., from a filtered array that ended up empty); CLI flag --target passed with no values producing an empty array; configuration computed at runtime that resolves to empty.

Related errors


AI-assisted analysis of parcel-bundler/parcel@59484858a1 (2026-08-13). Data as JSON: /api/errors/83dc7799c53058b8. Report an issue: GitHub.