vitest-dev/vitest · error · Error
stopChunkTrace cannot be called outside of the test file.
Error message
stopChunkTrace cannot be called outside of the test file.
What it means
startChunkTrace needs the running test file path to resolve where the chunk trace `.zip` will be written (via resolveTracesPath). When the command is invoked without an active test (testPath undefined) it refuses. Note: the error string says 'stopChunkTrace' but the throwing function is startChunkTrace — this is a copy-paste bug in the message, but the cause is calling startChunkTrace outside a test scope.
Solutions
- Ensure tracing chunk commands are only triggered while a test is actively running (the runner normally handles this — if you see it manually, you are calling an internal API out of context).
- Confirm the file is matched by the browser project's `include` and runs under `pool: 'browser'` so testPath is bound.
- If this surfaces from framework internals, file a Vitest issue with the runner state; do not call startChunkTrace yourself.
Defensive patterns
Strategy: validation
Validate before calling
// do not call startChunkTrace manually; ensure the runner is the only caller.
// if you must guard custom code:
if (!command.testPath) {
throw new Error('startChunkTrace must be called from within a running test')
} Type guard
function hasTestPath<T extends { testPath?: string }>(c: T): c is T & { testPath: string } {
return !!c.testPath
} Prevention
- Never call internal trace chunk APIs directly; rely on the runner.
- Ensure files run under pool: 'browser' with a valid include glob.
- Report occurrences via Vitest issues — these commands are runner-internal.
When it happens
Trigger: Runner/framework code invoking startChunkTrace during a phase that has no bound testPath (global setup/teardown, between tests, or when a test file is collected but not executing). Internal calls from the browser runner before a test context is established.
Common situations: Tracing enabled with a misconfigured runner that triggers chunk tracing outside test execution; custom test orchestration that calls startChunkTrace manually; partial support in a non-browser pool.
Related errors
- This command can only be called inside a test file.
- Browser is not initialized
- provider is not supported
- Browser provider is not defined for the project
- Cannot find iframe element. This is a bug in Vitest…
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/6e17a2d9052cdf11.
Report an issue: GitHub.
Appendix: source
Thrown at packages/browser-playwright/src/commands/trace.ts:36
await context.tracing.start({
screenshots: options.screenshots ?? true,
snapshots: options.snapshots ?? true,
sources: options.sources ?? true,
}).catch(() => {
provider.tracingContexts.delete(sessionId)
})
return
}
throw new TypeError(`The ${provider.name} provider does not support tracing.`)
}
export const startChunkTrace: BrowserCommand<[{ name: string; title: string }]> = async (
command,
{ name, title },
) => {
const { provider, sessionId, testPath, context } = command
if (!testPath) {
throw new Error(`stopChunkTrace cannot be called outside of the test file.`)
}
if (isPlaywrightProvider(provider)) {
if (!provider.tracingContexts.has(sessionId)) {
await startTracing(command)
}
const path = resolveTracesPath(command, name)
provider.pendingTraces.set(path, sessionId)
await context.tracing.startChunk({ name, title })
return
}
throw new TypeError(`The ${provider.name} provider does not support tracing.`)
}
export const stopChunkTrace: BrowserCommand<[{ name: string }]> = async (
context,
{ name },
) => {
if (isPlaywrightProvider(context.provider)) {View on GitHub (pinned to 1fa9837ec2)