{"record":{"id":"efadb0a438a3fe0c","repo":"avajs/ava","slug":"the-extensions-option-must-be-an-array","errorCode":null,"errorMessage":"The extensions option must be an array","messagePattern":"The extensions option must be an array","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/extensions.js","lineNumber":18,"sourceCode":"export default function resolveExtensions(configuredExtensions, providers = []) {\n\t// Combine all extensions possible for testing. Remove duplicate extensions.\n\tconst duplicates = new Set();\n\tconst seen = new Set();\n\n\tconst combine = extensions => {\n\t\tfor (const ext of extensions) {\n\t\t\tif (seen.has(ext)) {\n\t\t\t\tduplicates.add(ext);\n\t\t\t} else {\n\t\t\t\tseen.add(ext);\n\t\t\t}\n\t\t}\n\t};\n\n\tif (configuredExtensions !== undefined) {\n\t\tif (!Array.isArray(configuredExtensions)) {\n\t\t\tthrow new TypeError('The extensions option must be an array');\n\t\t}\n\n\t\tcombine(configuredExtensions);\n\t}\n\n\tfor (const {main} of providers) {\n\t\tcombine(main.extensions);\n\t}\n\n\tif (duplicates.size > 0) {\n\t\tthrow new Error(`Unexpected duplicate extensions in options: ’${[...duplicates].join('’, ’')}’.`);\n\t}\n\n\t// Unless the default was used by providers, as long as the extensions aren't explicitly set, set the default.\n\tif (configuredExtensions === undefined) {\n\t\tif (!seen.has('mjs')) {\n\t\t\tseen.add('mjs');\n\t\t}","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/extensions.js#L1-L36","documentation":"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.","triggerScenarios":"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']`.","commonSituations":"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.","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."],"exampleFix":"// before\nexport default {extensions: 'js'};\n// after\nexport default {extensions: ['js']};","handlingStrategy":"type-guard","validationCode":"if (config.extensions !== undefined && !Array.isArray(config.extensions)) {\n  throw new TypeError('extensions must be an array');\n}","typeGuard":"const isValidExtensions = v => v === undefined || (Array.isArray(v) && v.every(e => typeof e === 'string'));","tryCatchPattern":"try {\n  await run();\n} catch (err) {\n  if (err instanceof TypeError && err.message === 'The extensions option must be an array') {\n    console.error('Wrap the extensions value in an array in your AVA config');\n    process.exitCode = 1;\n  } else throw err;\n}","preventionTips":["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."],"tags":["configuration","type-error","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}