jestjs/jest · error · Error

'workerPath' must be absolute, got '${workerPath}'

Error message

'workerPath' must be absolute, got '${workerPath}'

What it means

Error "'workerPath' must be absolute, got '${workerPath}'" thrown in jestjs/jest.

Source

Thrown at packages/jest-worker/src/index.ts:100

 */
export class Worker {
  private _ending: boolean;
  private readonly _farm: Farm;
  private readonly _options: WorkerFarmOptions;
  private readonly _workerPool: WorkerPoolInterface;

  constructor(workerPath: string | URL, options?: WorkerFarmOptions) {
    this._options = {...options};
    this._ending = false;

    if (typeof workerPath !== 'string') {
      workerPath = workerPath.href;
    }

    if (workerPath.startsWith('file:')) {
      workerPath = fileURLToPath(workerPath);
    } else if (!isAbsolute(workerPath)) {
      throw new Error(`'workerPath' must be absolute, got '${workerPath}'`);
    }

    const workerPoolOptions: WorkerPoolOptions = {
      enableWorkerThreads: this._options.enableWorkerThreads ?? false,
      forkOptions: this._options.forkOptions ?? {},
      idleMemoryLimit: this._options.idleMemoryLimit,
      maxRetries: this._options.maxRetries ?? 3,
      numWorkers:
        this._options.numWorkers ?? Math.max(availableParallelism() - 1, 1),
      resourceLimits: this._options.resourceLimits ?? {},
      setupArgs: this._options.setupArgs ?? [],
      workerGracefulExitTimeout: this._options.workerGracefulExitTimeout,
    };

    if (this._options.WorkerPool) {
      this._workerPool = new this._options.WorkerPool(
        workerPath,
        workerPoolOptions,

View on GitHub (pinned to f49721c78e)

Solutions

  1. Pass an absolute path to the worker file, e.g. use require.resolve('./myWorker') or path.resolve(__dirname, 'myWorker.js') instead of a relative path.

When it happens

Trigger: Thrown at packages/jest-worker/src/index.ts:100 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03). Data as JSON: /data/errors/5c559108e735b760.json. Report an issue: GitHub.