avajs/ava · error · Error
Options have not yet been set
Error message
Options have not yet been set
What it means
AVA worker options (test file path, config, etc.) are injected by the AVA CLI at startup via set(). get() throws this Error when called before options were ever set — i.e. code that depends on the worker options module is running outside an AVA-managed test process, or runs before AVA's bootstrap.
Source
Thrown at lib/worker/options.js:4
let options = null;
export function get() {
if (!options) {
throw new Error('Options have not yet been set');
}
return options;
}
export function set(newOptions) {
if (options) {
throw new Error('Options have already been set');
}
options = newOptions;
}
View on GitHub (pinned to bbfd946322)
Solutions
- Ensure the code runs inside an AVA test process launched by the AVA CLI.
- Defer option access until test execution time (not at module import) so set() has already run.
- If building tooling around AVA, pass configuration explicitly instead of relying on worker options.
Example fix
// before
import {get} from './worker/options.js';
const opts = get(); // module top-level, options not set yet
// after
import {get} from './worker/options.js';
export function computeSomething() {
const opts = get(); // called during test run
...
} Defensive patterns
Strategy: try-catch
Validate before calling
import {get} from './worker/options.js';
function safeGet() {
try { return get(); } catch { return null; } // null means not running under AVA yet
} Try / catch
let opts;
try {
opts = get();
} catch (err) {
if (err.message === 'Options have not yet been set') {
opts = defaultOptions; // or defer until after AVA bootstrap
} else throw err;
} Prevention
- Access options lazily during test execution, not at module import time
- Only run code depending on worker options inside AVA test processes
- Avoid circular imports that reach options.js before bootstrap
When it happens
Trigger: Importing/using lib/worker/options.js get() from a module loaded at top level before AVA initializes the worker; running code that depends on AVA internals outside the AVA CLI; an internal module reading options during module import instead of lazily at test time.
Common situations: Running a test-support module directly with node; importing worker-internal modules from user code; circular imports causing options.js to be consulted before the CLI's bootstrap ran.
Related errors
- Options have already been set
- Shared worker is not yet available
- The `any` property of the second argument to `${assertion}`
- The second argument to `${assertion}` contains unexpected pr
- message
AI-assisted analysis of avajs/ava@bbfd946322 (2026-09-02).
Data as JSON: /api/errors/eb0c8df183a959fd.
Report an issue: GitHub.