avajs/ava · error · Error

The ’files’ configuration must be an array containing glob p

Error message

The ’files’ configuration must be an array containing glob patterns.

What it means

The `files` configuration selects which files AVA runs as tests; it must be a non-empty array of glob pattern strings. normalizeGlobs throws if `files` is defined but is not an array or is an empty array.

Source

Thrown at lib/globs.js:37

	normalizePattern,
	defaultIgnorePatterns,
	hasExtension,
	normalizeFileForMatching,
	normalizePatterns,
} from './glob-helpers.js';

const defaultIgnoredByWatcherPatterns = [
	'**/*.snap.md', // No need to rerun tests when the Markdown files change.
	'**/*.tsbuildinfo', // No need to rerun tests when TypeScript build info files change.
	'ava.config.js', // Config is not reloaded so avoid rerunning tests when it changes.
	'ava.config.mjs', // Config is not reloaded so avoid rerunning tests when it changes.
];

const buildExtensionPattern = extensions => extensions.length === 1 ? extensions[0] : `{${extensions.join(',')}}`;

export function normalizeGlobs({extensions, files: filePatterns, ignoredByWatcher: ignoredByWatcherPatterns, providers}) {
	if (filePatterns !== undefined && (!Array.isArray(filePatterns) || filePatterns.length === 0)) {
		throw new Error('The ’files’ configuration must be an array containing glob patterns.');
	}

	if (ignoredByWatcherPatterns !== undefined && (!Array.isArray(ignoredByWatcherPatterns) || ignoredByWatcherPatterns.length === 0)) {
		throw new Error('The ’watchMode.ignoreChanges’ configuration must be an array containing glob patterns.');
	}

	const extensionPattern = buildExtensionPattern(extensions);
	const defaultTestPatterns = [
		`test.${extensionPattern}`,
		`{src,source}/test.${extensionPattern}`,
		`**/__tests__/**/*.${extensionPattern}`,
		`**/*.spec.${extensionPattern}`,
		`**/*.test.${extensionPattern}`,
		`**/test-*.${extensionPattern}`,
		`**/test/**/*.${extensionPattern}`,
		`**/tests/**/*.${extensionPattern}`,
		'!**/__tests__/**/__{helper,fixture}?(s)__/**/*',
		'!**/test?(s)/**/{helper,fixture}?(s)/**/*',

View on GitHub (pinned to bbfd946322)

Solutions

  1. Wrap the pattern in an array: `files: ['test/**/*.test.js']`.
  2. Ensure the array is non-empty; remove code that yields `files: []`.
  3. If building patterns dynamically, validate length > 0 before assigning.
  4. Fall back to AVA's defaults by omitting `files` entirely rather than passing an empty array.

Example fix

// before
export default {files: 'test/**/*.js'};
// after
export default {files: ['test/**/*.js']};
Defensive patterns

Strategy: validation

Validate before calling

if (config.files !== undefined && (!Array.isArray(config.files) || config.files.length === 0)) {
  throw new TypeError('files must be a non-empty array of glob strings');
}

Type guard

const isValidFiles = v => v === undefined || (Array.isArray(v) && v.length > 0 && v.every(p => typeof p === 'string'));

Try / catch

try {
  await run();
} catch (err) {
  if (err.message.includes('’files’ configuration must be an array')) {
    console.error('Use files: [\'test/**/*.js\'] — an array, non-empty');
    process.exitCode = 1;
  } else throw err;
}

Prevention

When it happens

Trigger: Setting `files: 'test/**/*.js'` (a bare string instead of an array), `files: []`, or `files: null` with files defined, in ava.config.js/package.json or the programmatic API.

Common situations: Copying CLI glob strings directly into config without wrapping in an array; an empty array produced by filtered/generated config; editing package.json so files becomes an empty list.

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


AI-assisted analysis of avajs/ava@bbfd946322 (2026-09-02). Data as JSON: /api/errors/71df7a0a88df2c45. Report an issue: GitHub.