{"record":{"id":"5c43fcbeaf325ced","repo":"angular/angular-cli","slug":"package-dependency-name-already-exists-with-a","errorCode":null,"errorMessage":"Package dependency \"${name}\" already exists with a different specifier. \"${existingSpecifier}\" will be replaced with \"${specifier}\".","messagePattern":"Package dependency \"(.+?)\" already exists with a different specifier\\. \"(.+?)\" will be replaced with \"(.+?)\"\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/schematics/angular/utility/dependency.ts","lineNumber":201,"sourceCode":"      // Section is not present. The dependency can be added to a new object literal for the section.\n      manifest[type] = { [name]: specifier };\n    } else {\n      const existingSpecifier = dependencySection[name];\n\n      if (existingSpecifier === specifier) {\n        // Already present with same specifier\n        return;\n      }\n\n      if (existingSpecifier) {\n        // Already present but different specifier\n\n        if (existing === ExistingBehavior.Skip) {\n          return;\n        }\n\n        // ExistingBehavior.Replace is the only other behavior currently\n        context.logger.warn(\n          `Package dependency \"${name}\" already exists with a different specifier. ` +\n            `\"${existingSpecifier}\" will be replaced with \"${specifier}\".`,\n        );\n      }\n\n      // Add new dependency in alphabetical order\n      const entries = Object.entries(dependencySection);\n      entries.push([name, specifier]);\n      entries.sort((a, b) => a[0].localeCompare(b[0]));\n      manifest[type] = Object.fromEntries(entries);\n    }\n\n    tree.overwrite(packageJsonPath, JSON.stringify(manifest, null, 2));\n\n    const installPaths = installTasks.get(context) ?? new Set<string>();\n    if (\n      install === InstallBehavior.Always ||\n      (install === InstallBehavior.Auto && !installPaths.has(packageJsonPath))","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/utility/dependency.ts#L183-L219","documentation":"addDependency (packages/schematics/angular/utility/dependency.ts) inserts a package into package.json. When the package already exists with a different version specifier, the default behavior (ExistingBehavior.Replace) warns that the existing specifier is being overwritten with the new one.","triggerScenarios":"Any schematic calling addDependency (directly or via addDependenciesToPackageJson) where package.json already lists the package under a different range, e.g. \"~16.2.0\" present while the schematic installs \"^17.0.0\".","commonSituations":"ng update / ng add flows where the workspace has a manually pinned or locally patched version of a dependency (e.g. @angular/core, zone.js, typescript) that differs from the schematic's target version.","solutions":["Accept the replacement if the schematic's version is what you want; commit the updated package.json","If you need to keep your specifier, pin it back after the schematic runs or pre-update the dependency to a compatible range before running","Review the package.json diff after ng update/ng add to confirm no unexpected version changes"],"exampleFix":"// before (package.json)\n\"@angular/core\": \"~16.2.0\"\n// after schematic run (warned replacement)\n\"@angular/core\": \"^17.0.0\"","handlingStrategy":"validation","validationCode":"// before running schematics that add deps, diff installed versions against expected\nconst pkg = require('./package.json');\nconst name = '@angular/core';\nconst expectedRange = '^17.0.0';\nif (pkg.dependencies?.[name] && pkg.dependencies[name] !== expectedRange) {\n  console.warn(`${name} will be replaced: ${pkg.dependencies[name]} -> ${expectedRange}`);\n}","typeGuard":"function dependencyWillChange(pkgJson, name, specifier) {\n  const current = pkgJson?.dependencies?.[name] ?? pkgJson?.devDependencies?.[name];\n  return typeof current === 'string' && current !== specifier;\n}","tryCatchPattern":null,"preventionTips":["Avoid hand-pinned versions of Angular-managed packages; let ng update manage them","Review package.json diffs after every ng update / ng add","Update dependencies to a range compatible with the schematic's target before running migrations"],"tags":["angular","schematics","dependencies","package-json","version-conflict"],"backgroundTag":"dependency-specifier-replaced","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}