avajs/ava · error · TypeError
The extensions option must be an array
Error message
The extensions option must be an array
What it means
The `extensions` option tells AVA which file extensions to treat as test files. It must be an array of strings; if `resolveExtensions` receives a configured value that is not an array, it throws this TypeError immediately.
Source
Thrown at lib/extensions.js:18
export default function resolveExtensions(configuredExtensions, providers = []) {
// Combine all extensions possible for testing. Remove duplicate extensions.
const duplicates = new Set();
const seen = new Set();
const combine = extensions => {
for (const ext of extensions) {
if (seen.has(ext)) {
duplicates.add(ext);
} else {
seen.add(ext);
}
}
};
if (configuredExtensions !== undefined) {
if (!Array.isArray(configuredExtensions)) {
throw new TypeError('The extensions option must be an array');
}
combine(configuredExtensions);
}
for (const {main} of providers) {
combine(main.extensions);
}
if (duplicates.size > 0) {
throw new Error(`Unexpected duplicate extensions in options: ’${[...duplicates].join('’, ’')}’.`);
}
// Unless the default was used by providers, as long as the extensions aren't explicitly set, set the default.
if (configuredExtensions === undefined) {
if (!seen.has('mjs')) {
seen.add('mjs');
}View on GitHub (pinned to bbfd946322)
Solutions
- Change the value to an array: `extensions: ['js', 'mjs']`.
- If a single extension, still wrap it: `extensions: ['ts']`.
- Split comma-separated strings: `'js,mjs'.split(',')`.
- Add Array.isArray validation in a config factory before returning.
Example fix
// before
export default {extensions: 'js'};
// after
export default {extensions: ['js']}; Defensive patterns
Strategy: type-guard
Validate before calling
if (config.extensions !== undefined && !Array.isArray(config.extensions)) {
throw new TypeError('extensions must be an array');
} Type guard
const isValidExtensions = v => v === undefined || (Array.isArray(v) && v.every(e => typeof e === 'string'));
Try / catch
try {
await run();
} catch (err) {
if (err instanceof TypeError && err.message === 'The extensions option must be an array') {
console.error('Wrap the extensions value in an array in your AVA config');
process.exitCode = 1;
} else throw err;
} Prevention
- Always write extensions as an array, even for one item.
- Never copy CLI-style comma strings into the config option.
- Validate config shape with a schema library before running.
- Keep AVA config typed (JSDoc/TS) so editors flag non-array values.
When it happens
Trigger: Passing `extensions: 'js'` (a string), `extensions: {main: ['js']}`, or any non-array value in ava.config.js/package.json or to the programmatic API, instead of an array like `extensions: ['js', 'mjs']`.
Common situations: Config typo where quotes wrap a comma list ('js, mjs'); object-shaped config copied from another tool; a config factory returning a wrong type after refactoring.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- The ’environmentVariables’ configuration must be an object c
- ${fileForErrorMessage} must export a plain object or factory
- Unexpected duplicate extensions in options: ’${[...duplicate
- The ’files’ configuration must be an array containing glob p
- The ’watchMode.ignoreChanges’ configuration must be an array
AI-assisted analysis of avajs/ava@bbfd946322 (2026-09-02).
Data as JSON: /api/errors/efadb0a438a3fe0c.
Report an issue: GitHub.