parcel-bundler/parcel · error · ThrowableDiagnostic

More than one target is not supported in serve mode

Error message

More than one target is not supported in serve mode

What it means

Thrown by TargetRequest.resolve() when serve mode (parcel serve / serveOptions) is active and more than one browser-context target is resolved. Serve mode is designed for a single browser target (dev server), so multiple browser targets are rejected. Non-browser targets (node, electron) are allowed alongside serve mode since they don't conflict with the browser serving.

Source

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

            }

            return target;
          })
          .filter(
            target => !skipTarget(target.name, exclusiveTarget, target.source),
          );
      }

      let serve = this.options.serveOptions;
      if (
        serve &&
        targets.length > 0 &&
        targets.every(t => BROWSER_ENVS.has(t.env.context))
      ) {
        // In serve mode, we only support a single browser target. If the user
        // provided more than one, or the matching target is not a browser, throw.
        if (targets.length > 1) {
          throw new ThrowableDiagnostic({
            diagnostic: {
              message: `More than one target is not supported in serve mode`,
              origin: '@parcel/core',
            },
          });
        }
        targets[0].distDir = toProjectPath(
          this.options.projectRoot,
          serve.distDir,
        );
      }
    } else {
      targets = Array.from(packageTargets.values())
        .filter(Boolean)
        .filter(descriptor => {
          return (
            descriptor &&
            !skipTarget(descriptor.name, exclusiveTarget, descriptor.source)

View on GitHub (pinned to 59484858a1)

Solutions

  1. Use parcel build instead of parcel serve if you need multiple browser targets — serve mode is for single-target dev serving.
  2. Reduce to a single browser target for serve mode: pass --target <name> to select one.
  3. If you have mixed browser and node targets, the error only fires when ALL are browser — but serve mode still serves only one; consolidate.
  4. In package.json, separate dev targets (single browser) from build targets (multiple).

Example fix

// before — package.json
{
  "targets": {
    "modern": { "context": "browser", "distDir": "dist/modern" },
    "legacy":  { "context": "browser", "distDir": "dist/legacy" }
  }
}
// CLI: parcel serve src/index.html  // ERROR: 2 browser targets

// after — select one for serve
parcel serve --target modern src/index.html
// or use build for both
parcel build src/index.html
Defensive patterns

Strategy: validation

Validate before calling

function validateServeModeSingleBrowserTarget(targets, serveOptions) {
  if (!serveOptions) return;
  const BROWSER_ENVS = new Set(['browser', 'web-worker', 'service-worker', 'worklet']);
  const browserTargets = targets.filter(t => BROWSER_ENVS.has(t.env?.context));
  if (browserTargets.length > 1) {
    throw new Error(`Serve mode requires exactly one browser target; found ${browserTargets.length}: ${browserTargets.map(t => t.name).join(', ')}`);
  }
}

Prevention

When it happens

Trigger: After targets are resolved, if this.options.serveOptions is truthy, targets.length > 0, and every target's env.context is in BROWSER_ENVS, then targets.length > 1 triggers the error. The check only fires when all targets are browser-type.

Common situations: Running parcel serve with package.json that defines multiple browser targets; passing multiple targets via --target that are all browser context; using serve mode with a default config that resolves to multiple browser targets; migrating from build mode to serve mode without consolidating targets.

Related errors


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