{"record":{"id":"0b16961ac31022e0","repo":"avajs/ava","slug":"the-environmentvariables-configuration-must-be-a","errorCode":null,"errorMessage":"The ’environmentVariables’ configuration must be an object containing string values.","messagePattern":"The ’environmentVariables’ configuration must be an object containing string values\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/environment-variables.js","lineNumber":8,"sourceCode":"export default function validateEnvironmentVariables(environmentVariables) {\n\tif (!environmentVariables) {\n\t\treturn {};\n\t}\n\n\tfor (const value of Object.values(environmentVariables)) {\n\t\tif (typeof value !== 'string') {\n\t\t\tthrow new TypeError('The ’environmentVariables’ configuration must be an object containing string values.');\n\t\t}\n\t}\n\n\treturn environmentVariables;\n}\n","sourceCodeStart":1,"sourceCodeEnd":14,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/environment-variables.js#L1-L14","documentation":"The `environmentVariables` configuration option must be a plain object whose values are all strings, since its entries are passed to child test processes as actual environment variables. If any value is not a string, loadCli throws this TypeError during configuration validation.","triggerScenarios":"Setting `environmentVariables` in ava.config.js/package.json to an object containing a non-string value — e.g. `environmentVariables: {PORT: 3000}` or `{DEBUG: true}` — then running the AVA CLI.","commonSituations":"Using numeric ports or booleans in config; YAML/JSON5 config files where unquoted values become numbers; programmatic `ava` API calls passing non-string env values.","solutions":["Quote or convert every value to a string: `environmentVariables: {PORT: '3000'}`.","Use String() or template literals for computed values: `PORT: String(port)`.","Validate config values with typeof before passing them to AVA.","Check for build tooling (YAML loaders, dotenv munging) that turns quoted values into numbers/booleans."],"exampleFix":"// before\nenvironmentVariables: {PORT: 3000, DEBUG: true}\n// after\nenvironmentVariables: {PORT: '3000', DEBUG: 'true'}","handlingStrategy":"type-guard","validationCode":"const env = config.environmentVariables;\nif (env !== undefined) {\n  for (const [k, v] of Object.entries(env)) {\n    if (typeof v !== 'string') throw new TypeError(`environmentVariables.${k} must be a string (got ${typeof v})`);\n  }\n}","typeGuard":"const isValidEnvVars = v => v === undefined || (typeof v === 'object' && v !== null && Object.values(v).every(x => typeof x === 'string'));","tryCatchPattern":"try {\n  await run();\n} catch (err) {\n  if (err instanceof TypeError && err.message.includes('environmentVariables')) {\n    console.error('Fix environmentVariables values to be strings in your AVA config');\n    process.exitCode = 1;\n  } else throw err;\n}","preventionTips":["Always stringify numeric/boolean env values: String(port), port + ''.","Quote values in YAML/JSON config files.","Add a schema check (e.g. with a validator) over your AVA config in CI.","Keep environmentVariables entries minimal and type-annotated in JS config."],"tags":["configuration","type-error","validation","environment"],"backgroundTag":"schema-validation-failed","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}