{"record":{"id":"53afe5eb0569d03c","repo":"avajs/ava","slug":"conflicting-configuration-in-fileforerrormessage-53afe5","errorCode":null,"errorMessage":"Conflicting configuration in ${fileForErrorMessage} and package.json","messagePattern":"Conflicting configuration in (.+?) and package\\.json","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/load-config.js","lineNumber":135,"sourceCode":"\t\t\tif (jsonFile !== null) {\n\t\t\t\tunsupportedFiles.push(jsonFile);\n\t\t\t}\n\n\t\t\t[{config: fileConf, fileForErrorMessage, configFile} = {config: NO_SUCH_FILE, fileForErrorMessage: undefined}, ...conflicting] = results.filter(result => result !== null);\n\n\t\t\tsearchDir = path.dirname(searchDir);\n\t\t} while (fileConf === NO_SUCH_FILE && searchDir !== stopAt);\n\t}\n\n\tif (conflicting.length > 0) {\n\t\tthrow new Error(`Conflicting configuration in ${fileForErrorMessage} and ${conflicting.map(({fileForErrorMessage}) => fileForErrorMessage).join(' & ')}`);\n\t}\n\n\tif (fileConf !== NO_SUCH_FILE) {\n\t\tif (allowConflictWithPackageJson) {\n\t\t\tpackageConf = {};\n\t\t} else if (Object.keys(packageConf).length > 0) {\n\t\t\tthrow new Error(`Conflicting configuration in ${fileForErrorMessage} and package.json`);\n\t\t}\n\n\t\tif (!isPlainObject(fileConf) && typeof fileConf !== 'function') {\n\t\t\tthrow new TypeError(`${fileForErrorMessage} must export a plain object or factory function`);\n\t\t}\n\n\t\tif (typeof fileConf === 'function') {\n\t\t\tfileConf = await fileConf({projectDir});\n\n\t\t\tif (!isPlainObject(fileConf)) {\n\t\t\t\tthrow new TypeError(`Factory method exported by ${fileForErrorMessage} must return a plain object`);\n\t\t\t}\n\t\t}\n\n\t\tif ('ava' in fileConf) {\n\t\t\tthrow new Error(`Encountered ’ava’ property in ${fileForErrorMessage}; avoid wrapping the configuration`);\n\t\t}\n\t}","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/load-config.js#L117-L153","documentation":"AVA refuses to run with both a dedicated config file (ava.config.js/mjs/cjs, .avarc) and an `ava` key in package.json, since it cannot decide which wins — unless the file explicitly opts out (a factory config can accept package.json to allow merging). loadConfig throws this when a config file is found and packageConf still has keys.","triggerScenarios":"Having ava.config.js at the project root while package.json still contains an `\"ava\": {...}` section, then running AVA (with no explicit allowConflict setting).","commonSituations":"Migrating config from package.json to a standalone file but forgetting to delete the old `ava` block; scaffolding tools adding both; partial cleanup after an AVA version upgrade.","solutions":["Delete the `ava` key from package.json, keeping the dedicated config file.","Or delete the config file and keep only the package.json `ava` section.","If using a config factory, merge intentionally: `export default ({projectDir}) => ({...packageJsonAvaOptions})`.","Pass --config explicitly to select one file when multiple exist."],"exampleFix":"// before\n// package.json: {\"ava\": {\"files\": [\"test/**/*.js\"]}} and ava.config.js exists\n// after: remove the \"ava\" key from package.json\n$ node -e \"delete require('./package.json').ava\"","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nconst pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));\nconst hasConfigFile = fs.existsSync('ava.config.js') || fs.existsSync('ava.config.mjs') || fs.existsSync('ava.config.cjs');\nif (hasConfigFile && pkg.ava && Object.keys(pkg.ava).length > 0) {\n  throw new Error('Remove the \"ava\" key from package.json or delete the config file');\n}","typeGuard":"const hasNoConfigConflict = ({pkg, hasConfigFile}) => !(hasConfigFile && pkg?.ava && Object.keys(pkg.ava).length > 0);","tryCatchPattern":"try {\n  await run();\n} catch (err) {\n  if (err.message.includes('and package.json')) {\n    console.error('AVA found both a config file and an \"ava\" key in package.json — keep one');\n    process.exitCode = 1;\n  } else throw err;\n}","preventionTips":["When moving config to a file, delete the package.json \"ava\" key in the same commit.","Add a lint/CI check that flags both sources being present.","Know that a config factory can opt into package.json merging; use it deliberately.","Scaffold tools should only emit one config source."],"tags":["configuration","conflict","package-json"],"backgroundTag":"conflicting-config-files","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}