angular/angular-cli · error · CommandError

Unable to install packages

Error message

Unable to install packages

What it means

During `ng update`, the package-install task calls the package manager's install(); any failure (network outage, registry auth, lockfile conflicts, disk issues) is swallowed and rethrown as the generic CommandError 'Unable to install packages', hiding the underlying cause.

Source

Thrown at packages/angular/cli/src/commands/update/cli.ts:598

              maxRetries: 3,
            });
          } catch (e) {
            assertIsError(e);
            if (e.code === 'ENOENT') {
              task.skip('Cleaning not required. Node modules directory not found.');
            }
          }
        },
      },
      {
        title: 'Installing packages',
        async task() {
          try {
            await packageManager.install({
              ignorePeerDependencies,
            });
          } catch (e) {
            throw new CommandError('Unable to install packages');
          }
        },
      },
    ]);
    try {
      await tasks.run();
      // Clear Node's module resolution path cache to prevent stale lookups
      // when resolving migration package paths.
      const Module = require('node:module');
      if (Module && Module._pathCache) {
        Module._pathCache = Object.create(null);
      }
    } catch (e) {
      if (originalPackageJsonContent !== undefined) {
        try {
          await fs.writeFile(packageJsonPath, originalPackageJsonContent, 'utf8');
          logger.info('Restored package.json to its original state.');
        } catch (restoreError) {

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Check network/registry access: `npm ping` / verify .npmrc registry and auth tokens.
  2. Run `npm install` (or yarn/pnpm) manually in the workspace to see the real error.
  3. Fix peer dependency conflicts or use --force/--legacy-peer-deps appropriately, then retry ng update.
  4. Delete node_modules and lockfile issues (`rm -rf node_modules package-lock.json`) and retry.

Example fix

// before (private scope without auth)
ng update @myco/ui
// error: Unable to install packages
// after: add token to .npmrc
// @myco:registry=https://npm.myco.io/
// npm.myco.io/:_authToken=${NPM_TOKEN}
ng update @myco/ui
Defensive patterns

Strategy: try-catch

Validate before calling

import { execSync } from 'child_process';
execSync('npm ping'); // fail fast on registry unavailability before ng update
execSync('npm ls --depth=0');

Try / catch

try {
  await ngUpdate(packages);
} catch (e) {
  if (String(e.message) === 'Unable to install packages') {
    console.error('ng update hid the real cause; run npm install manually to see it:', e);
    execSync('npm install --verbose', { stdio: 'inherit' });
  } else throw e;
}

Prevention

When it happens

Trigger: packageManager.install({ ignorePeerDependencies }) throws — offline machine, private registry requiring auth, unresolved peer dependency conflicts, corrupted node_modules, or npm/yarn/pnpm CLI errors.

Common situations: Corporate proxies/VPNs blocking registry access; missing NPM_TOKEN for @private scopes; partially installed node_modules; incompatible peer dependencies with ignorePeerDependencies=false.

Related errors


AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30). Data as JSON: /api/errors/69cd9ecae62e002e. Report an issue: GitHub.