microsoft/playwright · error · Error

Cannot find .trace file

Error message

Cannot find .trace file

What it means

Thrown by TraceLoader.load when the loaded trace archive (or backend entry list) contains no entries whose name matches `*.trace`. The loader scans backend.entryNames() for a regex match and, finding none, cannot proceed because there is no trace event stream to modernize.

Source

Thrown at packages/isomorphic/trace/traceLoader.ts:55

  constructor() {
  }

  async load(backend: TraceLoaderBackend, traceFile?: string, unzipProgress?: (done: number, total: number) => void) {
    this._backend = backend;

    const prefix = traceFile?.match(/(.+)\.trace$/)?.[1];
    const prefixes: string[] = [];
    let hasSource = false;
    for (const entryName of await this._backend.entryNames()) {
      const match = entryName.match(/(.+)\.trace$/);
      if (match && (!prefix || prefix  === match[1]))
        prefixes.push(match[1] || '');
      if (entryName.startsWith('src/') || entryName.includes('src@'))
        hasSource = true;
    }
    if (!prefixes.length)
      throw new Error('Cannot find .trace file');

    this._snapshotStorage = new SnapshotStorage();

    // 3 * ordinals progress increments below.
    const total = prefixes.length * 3;
    let done = 0;
    for (const prefix of prefixes) {
      const contextEntry = createEmptyContext();
      contextEntry.hasSource = hasSource;
      const modernizer = new TraceModernizer(contextEntry, this._snapshotStorage);

      const trace = await this._backend.readText(prefix + '.trace') || '';
      modernizer.appendTrace(trace);
      unzipProgress?.(++done, total);

      const network = await this._backend.readText(prefix + '.network') || '';
      modernizer.appendTrace(network);
      unzipProgress?.(++done, total);

View on GitHub (pinned to c8fc3bf8d3)

Solutions

  1. Verify the file is a valid Playwright trace (re-export via `--trace on`).
  2. Confirm the trace path is correct and the file is not empty/corrupted.
  3. If using a custom backend, ensure entryNames() returns names ending in `.trace`.
  4. Re-record the trace to rule out capture failure.

Example fix

// before
traceLoader.load(backend, 'maybe-a-screenshot.png');

// after
const tracePath = 'trace.zip';
if (!tracePath.endsWith('.zip') && !tracePath.endsWith('.trace'))
  throw new Error(`Expected a .zip/.trace file, got ${tracePath}`);
traceLoader.load(backend, tracePath);
Defensive patterns

Strategy: validation

Validate before calling

async function ensureTraceEntry(backend: TraceLoaderBackend) {
  const names = await backend.entryNames();
  if (!names.some(n => n.endsWith('.trace')))
    throw new Error('Selected archive has no .trace entry; re-record with --trace on');
}

Type guard

async function archiveHasTrace(backend: TraceLoaderBackend): Promise<boolean> {
  return (await backend.entryNames()).some(n => n.endsWith('.trace'));
}

Try / catch

try {
  await traceLoader.load(backend, file);
} catch (e) {
  if (/Cannot find \.trace file/.test(e.message)) {
    console.error(`${file} is not a valid Playwright trace. Re-record with --trace on.`);
    process.exit(2);
  }
  throw e;
}

Prevention

When it happens

Trigger: Opening a non-trace file (e.g. a .zip with unrelated content), a corrupted/partial trace archive, a trace exported without the `.trace` resource, or pointing the trace viewer at a directory backend whose entries lack the `.trace` suffix.

Common situations: Passing the wrong file to `npx playwright show-trace`; an interrupted trace write that never flushed the `.trace` entry; a custom TraceLoaderBackend returning unexpected entry names; bundling a `.trace` inside another archive format.

Related errors


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