Automattic/mongoose · error · Error
Could not normalize ref path, chunk ${chunk} not in populate
Error message
Could not normalize ref path, chunk ${chunk} not in populated path What it means
Error "Could not normalize ref path, chunk ${chunk} not in populated path" thrown in Automattic/mongoose.
Source
Thrown at lib/helpers/populate/modelNamesFromRefPath.js:54
let _refPath = '';
let _remaining = refPath;
// 2nd, 4th, etc. will be numeric props. For example: `[ 'a', '.0.', 'b' ]`
for (let i = 0; i < chunks.length; i += 2) {
const chunk = chunks[i];
if (
_remaining.length >= chunk.length + 1 &&
_remaining.charAt(chunk.length) === '.' &&
_remaining.slice(0, chunk.length) === chunk
) {
_refPath += _remaining.substring(0, chunk.length) + chunks[i + 1];
_remaining = _remaining.substring(chunk.length + 1);
} else if (i === chunks.length - 1) {
_refPath += _remaining;
_remaining = '';
break;
} else {
throw new Error('Could not normalize ref path, chunk ' + chunk + ' not in populated path');
}
}
const refValue = mpath.get(_refPath, doc, lookupLocalFields);
let modelNames = Array.isArray(refValue) ? refValue : [refValue];
modelNames = utils.array.flatten(modelNames);
return modelNames;
}
const refValue = mpath.get(refPath, doc, lookupLocalFields);
let modelNames;
if (modelSchema != null && Object.hasOwn(modelSchema.virtuals, refPath)) {
modelNames = [modelSchema.virtuals[refPath].applyGetters(void 0, doc)];
} else {
modelNames = Array.isArray(refValue) ? refValue : [refValue];
}
View on GitHub (pinned to 49cdab0136)
When it happens
Trigger: Thrown at lib/helpers/populate/modelNamesFromRefPath.js:54 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21).
Data as JSON: /api/errors/3f8ffec1a303b16d.
Report an issue: GitHub.