microsoft/monaco-editor · error · Error
Cannot merge ${fieldName}: property '${key}' already exists
Error message
Cannot merge ${fieldName}: property '${key}' already exists in target with value '${target[key]}', would be overridden with '${value}' What it means
Thrown by objectMergeThrowIfSet while merging monaco-editor-core's dependencies into monaco-editor's package.json during release packaging. The merge copies every dependency key from core into monaco-editor's dependencies, but refuses to overwrite any key that already exists in the target. This is a deliberate fail-fast guard: a collision means both packages pin the same dependency name (possibly to different versions), and silently picking one would hide a version-conflict bug. The error message names the colliding key and both values.
Source
Thrown at scripts/ci/build-monaco-editor-pkg.ts:105
await run('npm run build', { cwd: rootPath });
await run('npm test', { cwd: rootPath });
await run('npm run compile', { cwd: resolve(rootPath, 'webpack-plugin') });
await run('npm run package-for-smoketest-webpack', { cwd: rootPath });
await run('npm run package-for-smoketest-esbuild', { cwd: rootPath });
await run('npm run package-for-smoketest-vite', { cwd: rootPath });
await run('npm run smoketest', { cwd: rootPath });
// npm package is now ready to be published in ./out/monaco-editor
});
}
function objectMergeThrowIfSet(
target: Record<string, any>,
source: Record<string, any>,
fieldName: string
): void {
for (const [key, value] of Object.entries(source)) {
if (key in target) {
throw new Error(
`Cannot merge ${fieldName}: property '${key}' already exists in target with value '${target[key]}', would be overridden with '${value}'`
);
}
target[key] = value;
}
}
prepareMonacoEditorReleaseStableOrNightly();
View on GitHub (pinned to ca1b42dc89)
Solutions
- Read the colliding key and the two versions from the error message, then decide which version is correct and remove the duplicate from one package's dependencies so they no longer both declare it.
- If the versions should match, align monaco-editor's pin to monaco-editor-core's pin (or vice versa) and drop one of the entries.
- Re-run the build after editing — the merge only proceeds once no key collides.
- If the collision is intentional and you accept the core version, remove the entry from monaco-editor's package.json dependencies before running the script.
Example fix
// before — monaco-editor package.json dependencies has:
"dependencies": { "some-lib": "^1.0.0" }
// and monaco-editor-core also ships "some-lib": "^2.0.0" -> throws
// after — drop the duplicate from monaco-editor so core's version wins:
"dependencies": {} Defensive patterns
Strategy: validation
Validate before calling
function assertNoDependencyCollision(target: Record<string,string>, source: Record<string,string>) {
const collisions = Object.keys(source).filter(k => k in target);
if (collisions.length) {
for (const k of collisions) {
console.error(`Collision on '${k}': monaco-editor=${target[k]} core=${source[k]}`);
}
process.exit(2);
}
}
// run this against the two package.json dependency maps before invoking the build Type guard
function dependencyMapsCompatible(target: Record<string, string>, source: Record<string, string>): boolean {
return Object.keys(source).every(k => !(k in target) || target[k] === source[k]);
} Prevention
- Keep monaco-editor's package.json dependencies minimal so they rarely overlap with core's.
- Add a CI check that diffs the two dependency lists whenever either package.json changes.
- When core adds a dependency, audit monaco-editor's package.json in the same PR.
When it happens
Trigger: A release build where monaco-editor's package.json declares a dependency (e.g. a transitive lib also pinned by VS Code core) whose name also appears in monaco-editor-core's dependencies. Happens when core picks up a new dependency, or when monaco-editor adds a dependency that core already ships.
Common situations: VS Code core added/changed a dependency after a monaco-editor version bump; a manual edit to monaco-editor's package.json dependencies duplicated a core dependency; dependency alignment drift between the two packages during a release.
Related errors
- Invalid argument
- Invalid argument
- Missing PRERELEASE_VERSION in process.env
- Missing VSCODE_REF in process.env
AI-assisted analysis of microsoft/monaco-editor@ca1b42dc89 (2026-08-13).
Data as JSON: /api/errors/36f2e3de4a3a55b3.
Report an issue: GitHub.