parcel-bundler/parcel · error · Error

Cannot add a worker call if workerfarm is ending.

Error message

Cannot add a worker call if workerfarm is ending.

What it means

Thrown by WorkerFarm.addCall when this.ending is true — i.e. the farm has been told to shut down (end()/terminate()) and refuses to enqueue new work. This prevents new promises from being created against a farm that will never process them.

Source

Thrown at packages/core/workers/src/WorkerFarm.js:422

        result = errorResponseFromError(e);
      }
    }

    if (awaitResponse) {
      if (worker) {
        worker.send(result);
      } else {
        if (result.contentType === 'error') {
          throw new ThrowableDiagnostic({diagnostic: result.content});
        }
        return result.content;
      }
    }
  }

  addCall(method: string, args: Array<any>): Promise<any> {
    if (this.ending) {
      throw new Error('Cannot add a worker call if workerfarm is ending.');
    }

    return new Promise((resolve, reject) => {
      this.callQueue.push({
        method,
        args: args,
        retries: 0,
        resolve,
        reject,
      });
      this.processQueue();
    });
  }

  async end(): Promise<void> {
    this.ending = true;

    await Promise.all(

View on GitHub (pinned to 59484858a1)

Solutions

  1. Do not call the farm after end()/terminate(); track lifecycle and gate new calls.
  2. Use WorkerFarm.getShared() so a single managed instance is reused across builds rather than manually ending it.
  3. Await farm.end() fully before discarding the reference and ensure no timers/listeners queue calls afterward.
  4. If late calls are legitimate, re-create the farm or get the shared instance again.

Example fix

// before
farm.end();
farm.run('transform', file); // -> Cannot add a worker call

// after
await farm.end();
const farm2 = WorkerFarm.getShared(); // fresh/shared instance
farm2.run('transform', file);
Defensive patterns

Strategy: validation

Validate before calling

function assertFarmAlive(farm) {
  if (farm.ending) throw new Error('WorkerFarm is ending; no new calls allowed.');
}
assertFarmAlive(farm);
farm.run('transform', file);

Type guard

function isFarmUsable(farm: { ending?: boolean }): boolean {
  return !farm.ending;
}

Try / catch

try { await farm.addCall(method, args); }
catch (e) {
  if (/Cannot add a worker call if workerfarm is ending/.test(e.message)) {
    // obtain a fresh/shared farm and retry, or abort gracefully
  } else throw e;
}

Prevention

When it happens

Trigger: Calling farm.run(...) or farm.addCall(...) after farm.end()/farm.terminate() has been invoked, or concurrently while the shutdown is in progress.

Common situations: A watch/build script that ends the farm then triggers a late plugin callback; concurrent code paths where shutdown races with queued work; reusing a WorkerFarm instance across builds instead of getting the shared one.

Related errors


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