usebruno/bruno · error · BrunoError
Invalid variable at index ${index}: expected an object
Error message
Invalid variable at index ${index}: expected an object What it means
Thrown inside the env.variables.forEach loop when a single variable entry is not an object. The index in the message pinpoints the offending slot in the variables array.
Source
Thrown at packages/bruno-app/src/utils/importers/bruno-environment.js:16
import { BrunoError } from 'utils/common/error';
import { buildEnvVariable, dedupeImportedSecrets } from 'utils/environments';
const validateBrunoEnvironment = (env) => {
if (!env || typeof env !== 'object') {
throw new BrunoError('Invalid environment: expected an object');
}
if (!Array.isArray(env.variables)) {
throw new BrunoError('Invalid environment: missing or invalid variables array');
}
// Validate each variable
env.variables.forEach((variable, index) => {
if (!variable || typeof variable !== 'object') {
throw new BrunoError(`Invalid variable at index ${index}: expected an object`);
}
if (!variable.name || typeof variable.name !== 'string') {
throw new BrunoError(`Invalid variable at index ${index}: missing or invalid name`);
}
});
const variables = env.variables.map((envVariable) => buildEnvVariable({ envVariable, withUuid: true }));
return {
name: env.name || 'Imported Environment',
variables: dedupeImportedSecrets(variables),
color: env.color
};
};
const processEnvironmentData = (data, fileName) => {
try {
// Handle new single-file format with environments arrayView on GitHub (pinned to 9bdd81c7bd)
Solutions
- Inspect the variables array at the reported index and replace the primitive/null with a full variable object.
- Remove empty slots if the variable is not needed.
- Re-export the environment from Bruno rather than hand-editing.
Example fix
// before
"variables": [ "BASE_URL", { "name": "KEY", "value": "v" } ]
// after
"variables": [
{ "name": "BASE_URL", "value": "https://api", "enabled": true },
{ "name": "KEY", "value": "v", "enabled": true }
] Defensive patterns
Strategy: validation
Validate before calling
env.variables.forEach((v, i) => {
if (!(v !== null && typeof v === 'object' && !Array.isArray(v))) {
throw new Error(`Variable at index ${i} is not an object`);
}
}); Type guard
function isVariableEntry(v) {
return v !== null && typeof v === 'object' && !Array.isArray(v);
} Try / catch
try {
validateBrunoEnvironment(env);
} catch (err) {
const m = err.message.match(/Invalid variable at index (\d+): expected an object/);
if (m) env.variables = env.variables.filter(isVariableEntry);
throw err;
} Prevention
- Filter out null/primitive slots before import.
- Re-export environments instead of hand-editing array contents.
- Validate each variable entry shape before import.
When it happens
Trigger: variables array contains a null, a string, a number, or any primitive at the reported index, e.g. [null, {"name":"X"}] fails at index 0; ["BASE_URL"] fails at index 0.
Common situations: Trailing commas producing null holes, copying a variable name as a bare string instead of an object, or partial exports that emit null for deleted variables.
Related errors
- Invalid environment: expected an object
- Invalid environment: missing or invalid variables array
- Invalid variable at index ${index}: missing or invalid name
- No files provided
- Error in environment ${index + 1} from ${fileName}: ${err.me
AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13).
Data as JSON: /api/errors/2cc9145d2182575a.
Report an issue: GitHub.