webpack/webpack · error · Error

${firstEntry.byProperty} and ${secondEntry.byProperty} for a

Error message

${firstEntry.byProperty} and ${secondEntry.byProperty} for a single property is not supported

What it means

During mergeEntries (the core of cleverMerge), when the second entry's base value is undefined but it carries a byProperty, and the first entry already has a different byProperty, the merge throws. A single property cannot be split across two different selectors during a two-object merge, just as it cannot during single-object parsing (error 242).

Source

Thrown at lib/util/cleverMerge.js:417

 */
const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
	switch (getValueType(secondEntry.base)) {
		case VALUE_TYPE_ATOM:
		case VALUE_TYPE_DELETE:
			// No need to consider firstEntry at all
			// second value override everything
			// = second.base + second.byProperty
			return secondEntry;
		case VALUE_TYPE_UNDEFINED:
			if (!firstEntry.byProperty) {
				// = first.base + second.byProperty
				return {
					base: firstEntry.base,
					byProperty: secondEntry.byProperty,
					byValues: secondEntry.byValues
				};
			} else if (firstEntry.byProperty !== secondEntry.byProperty) {
				throw new Error(
					`${firstEntry.byProperty} and ${secondEntry.byProperty} for a single property is not supported`
				);
			} else {
				// = first.base + (first.byProperty + second.byProperty)
				// need to merge first and second byValues
				/** @type {Map<string, T & O>} */
				const newByValues = new Map(firstEntry.byValues);
				for (const [key, value] of /** @type {ByValues} */ (
					secondEntry.byValues
				)) {
					const firstValue = getFromByValues(
						/** @type {ByValues} */
						(firstEntry.byValues),
						key
					);
					newByValues.set(
						key,
						mergeSingleValue(firstValue, value, internalCaching)

View on GitHub (pinned to 318421ea8a)

Solutions

  1. Ensure both merged objects use the same byProperty name for any shared property key.
  2. Pre-resolve one object's byProperty (via resolveByProperty) before merging so only one selector remains.
  3. Restructure so the shared property lives under a single selector across both objects.

Example fix

// before
const a = { byMode: { dev: { output: x } } };
const b = { byTarget: { web: { output: y } } };
const merged = cleverMerge(a, b); // throws
// after — same selector on both sides
const a = { byMode: { dev: { output: x } } };
const b = { byMode: { web: { output: y } } };
const merged = cleverMerge(a, b);
Defensive patterns

Strategy: validation

Validate before calling

// Before cleverMerge(a, b), check that for every shared property key,
// if both carry a byProperty they are the same string.
function compatibleByProperties(a, b) {
  const keys = new Set([...Object.keys(a), ...Object.keys(b)]);
  for (const k of keys) {
    if (k.startsWith('by')) continue;
    const aBy = findOwnerBy(a, k);
    const bBy = findOwnerBy(b, k);
    if (aBy && bBy && aBy !== bBy) {
      throw new Error(`'${k}' has ${aBy} in first and ${bBy} in second`);
    }
  }
}
function findOwnerBy(obj, prop) {
  for (const key of Object.keys(obj)) {
    if (key.startsWith('by') && typeof obj[key] === 'object') {
      for (const byVal of Object.keys(obj[key])) {
        if (obj[key][byVal] && typeof obj[key][byVal] === 'object' && prop in obj[key][byVal]) return key;
      }
    }
  }
  return null;
}

Prevention

When it happens

Trigger: Calling cleverMerge(first, second) where the same property key has a byProperty in `first` (e.g. byMode) and a different byProperty in `second` (e.g. byTarget), and second's base for that key is undefined (only selector-driven values). The VALUE_TYPE_UNDEFINED branch at cleverMerge.js:408 then hits the mismatch check at :416.

Common situations: Merging two webpack config objects each using different byProperty selectors for the same option. Layering rule configs or snapshot configs that independently parameterize the same field by different dimensions.

Related errors


AI-assisted analysis of webpack/webpack@318421ea8a (2026-08-03). Data as JSON: /data/errors/a5d2b8bd5530f786.json. Report an issue: GitHub.