avajs/ava · error · TypeError

Factory method exported by ${fileForErrorMessage} must retur

Error message

Factory method exported by ${fileForErrorMessage} must return a plain object

What it means

Guard in loadConfig: the configuration file exports a factory function, but its return value is not a plain object. The input at fault is the value returned by the exported factory — class instances, arrays, Maps, or primitives are rejected.

Source

Thrown at lib/load-config.js:146

		throw new Error(`Conflicting configuration in ${fileForErrorMessage} and ${conflicting.map(({fileForErrorMessage}) => fileForErrorMessage).join(' & ')}`);
	}

	if (fileConf !== NO_SUCH_FILE) {
		if (allowConflictWithPackageJson) {
			packageConf = {};
		} else if (Object.keys(packageConf).length > 0) {
			throw new Error(`Conflicting configuration in ${fileForErrorMessage} and package.json`);
		}

		if (!isPlainObject(fileConf) && typeof fileConf !== 'function') {
			throw new TypeError(`${fileForErrorMessage} must export a plain object or factory function`);
		}

		if (typeof fileConf === 'function') {
			fileConf = await fileConf({projectDir});

			if (!isPlainObject(fileConf)) {
				throw new TypeError(`Factory method exported by ${fileForErrorMessage} must return a plain object`);
			}
		}

		if ('ava' in fileConf) {
			throw new Error(`Encountered ’ava’ property in ${fileForErrorMessage}; avoid wrapping the configuration`);
		}
	}

	const config = {
		...defaults, nonSemVerExperiments: {}, ...fileConf, ...packageConf, projectDir, configFile,
	};

	if (
		'filterNodeArgumentsForWorkerThreads' in config
		&& typeof config.filterNodeArgumentsForWorkerThreads !== 'function'
	) {
		throw new Error(`filterNodeArgumentsForWorkerThreads from ${fileForErrorMessage} must be a function`);
	}

View on GitHub (pinned to bbfd946322)

Solutions

  1. Have the factory return a plain object literal (module.exports = () => ({files: [...]}))
  2. Remove class instances, Maps, or Sets from the returned config
  3. If no factory is needed, export a plain object directly
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/load-config.js:146 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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