microsoft/playwright · error · Error

Trace file not found: ${filePath}

Error message

Trace file not found: ${filePath}

What it means

Thrown by openTrace() when the resolved trace file path does not exist on disk (fs.existsSync returns false). The path is resolved with path.resolve before the check, so it is evaluated relative to the current working directory. This guards extractTrace and the trace loader from receiving a nonexistent input.

Source

Thrown at packages/playwright-core/src/tools/trace/traceUtils.ts:69

    return this.model.actions.find(a => a.callId === actionId);
  }
}

function ensureTraceOpen(): string {
  if (!fs.existsSync(traceDir))
    throw new Error(`No trace opened. Run 'npx playwright trace open <file>' first.`);
  return traceDir;
}

export async function closeTrace() {
  if (fs.existsSync(traceDir))
    await fs.promises.rm(traceDir, { recursive: true });
}

export async function openTrace(traceFile: string) {
  const filePath = path.resolve(traceFile);
  if (!fs.existsSync(filePath))
    throw new Error(`Trace file not found: ${filePath}`);
  await closeTrace();
  await fs.promises.mkdir(traceDir, { recursive: true });
  if (filePath.endsWith('.zip'))
    await extractTrace(filePath, traceDir);
  else
    await fs.promises.writeFile(path.join(traceDir, '.link'), filePath, 'utf-8');
}

export async function loadTrace(): Promise<LoadedTrace> {
  const dir = ensureTraceOpen();
  const linkFile = path.join(dir, '.link');
  let traceDir: string;
  let traceFile: string | undefined;
  if (fs.existsSync(linkFile)) {
    const tracePath = await fs.promises.readFile(linkFile, 'utf-8');
    traceDir = path.dirname(tracePath);
    traceFile = path.basename(tracePath);
  } else {

View on GitHub (pinned to c8fc3bf8d3)

Solutions

  1. Verify the file exists at the resolved path printed in the error.
  2. Use an absolute path to the trace file to avoid cwd issues.
  3. Re-download or re-generate the trace if it is missing.

Example fix

// before
npx playwright trace open ./traces/run.zip
// after
npx playwright trace open /home/user/project/traces/run.zip
Defensive patterns

Strategy: validation

Validate before calling

import fs from 'fs';
import path from 'path';
const filePath = path.resolve(traceFile);
if (!fs.existsSync(filePath)) {
  throw new Error(`Trace file not found: ${filePath}`);
}

Type guard

function isExistingFile(p: string): boolean {
  try { return fs.statSync(p).isFile(); } catch { return false; }
}

Prevention

When it happens

Trigger: Running `npx playwright trace open ./missing.zip` or any path that does not point to an existing file.

Common situations: Typo in the filename; relative path resolved from the wrong cwd; trace file was deleted or never downloaded; wrong path on CI vs local.

Related errors


AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12). Data as JSON: /api/errors/b6f3d9a8a81485ac. Report an issue: GitHub.