{"id":"a5d2b8bd5530f786","repo":"webpack/webpack","slug":"firstentry-byproperty-and-secondentry-byprope","errorCode":null,"errorMessage":"${firstEntry.byProperty} and ${secondEntry.byProperty} for a single property is not supported","messagePattern":"(.+?) and (.+?) for a single property is not supported","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/util/cleverMerge.js","lineNumber":417,"sourceCode":" */\nconst mergeEntries = (firstEntry, secondEntry, internalCaching) => {\n\tswitch (getValueType(secondEntry.base)) {\n\t\tcase VALUE_TYPE_ATOM:\n\t\tcase VALUE_TYPE_DELETE:\n\t\t\t// No need to consider firstEntry at all\n\t\t\t// second value override everything\n\t\t\t// = second.base + second.byProperty\n\t\t\treturn secondEntry;\n\t\tcase VALUE_TYPE_UNDEFINED:\n\t\t\tif (!firstEntry.byProperty) {\n\t\t\t\t// = first.base + second.byProperty\n\t\t\t\treturn {\n\t\t\t\t\tbase: firstEntry.base,\n\t\t\t\t\tbyProperty: secondEntry.byProperty,\n\t\t\t\t\tbyValues: secondEntry.byValues\n\t\t\t\t};\n\t\t\t} else if (firstEntry.byProperty !== secondEntry.byProperty) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`${firstEntry.byProperty} and ${secondEntry.byProperty} for a single property is not supported`\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// = first.base + (first.byProperty + second.byProperty)\n\t\t\t\t// need to merge first and second byValues\n\t\t\t\t/** @type {Map<string, T & O>} */\n\t\t\t\tconst newByValues = new Map(firstEntry.byValues);\n\t\t\t\tfor (const [key, value] of /** @type {ByValues} */ (\n\t\t\t\t\tsecondEntry.byValues\n\t\t\t\t)) {\n\t\t\t\t\tconst firstValue = getFromByValues(\n\t\t\t\t\t\t/** @type {ByValues} */\n\t\t\t\t\t\t(firstEntry.byValues),\n\t\t\t\t\t\tkey\n\t\t\t\t\t);\n\t\t\t\t\tnewByValues.set(\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tmergeSingleValue(firstValue, value, internalCaching)","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/webpack/webpack/blob/318421ea8ac81371f5171236a6efb63675576528/lib/util/cleverMerge.js#L399-L435","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure both merged objects use the same byProperty name for any shared property key.","Pre-resolve one object's byProperty (via resolveByProperty) before merging so only one selector remains.","Restructure so the shared property lives under a single selector across both objects."],"exampleFix":"// before\nconst a = { byMode: { dev: { output: x } } };\nconst b = { byTarget: { web: { output: y } } };\nconst merged = cleverMerge(a, b); // throws\n// after — same selector on both sides\nconst a = { byMode: { dev: { output: x } } };\nconst b = { byMode: { web: { output: y } } };\nconst merged = cleverMerge(a, b);","handlingStrategy":"validation","validationCode":"// Before cleverMerge(a, b), check that for every shared property key,\n// if both carry a byProperty they are the same string.\nfunction compatibleByProperties(a, b) {\n  const keys = new Set([...Object.keys(a), ...Object.keys(b)]);\n  for (const k of keys) {\n    if (k.startsWith('by')) continue;\n    const aBy = findOwnerBy(a, k);\n    const bBy = findOwnerBy(b, k);\n    if (aBy && bBy && aBy !== bBy) {\n      throw new Error(`'${k}' has ${aBy} in first and ${bBy} in second`);\n    }\n  }\n}\nfunction findOwnerBy(obj, prop) {\n  for (const key of Object.keys(obj)) {\n    if (key.startsWith('by') && typeof obj[key] === 'object') {\n      for (const byVal of Object.keys(obj[key])) {\n        if (obj[key][byVal] && typeof obj[key][byVal] === 'object' && prop in obj[key][byVal]) return key;\n      }\n    }\n  }\n  return null;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Align byProperty selector names across objects you intend to merge.","Use resolveByProperty to collapse one selector dimension before merging.","Test config merges in isolation to surface selector conflicts early."],"tags":["config","merge","byproperty","clevermerge"],"analyzedSha":"318421ea8ac81371f5171236a6efb63675576528","analyzedAt":"2026-08-03T19:39:56.731Z","schemaVersion":2}