angular/angular-cli · warning

Failed to clean up temporary dependency '${packageName}': ${

Error message

Failed to clean up temporary dependency '${packageName}': ${error instanceof Error ? error.message : error}

What it means

During `ng add`, the CLI temporarily installs a package to inspect it, then tries to remove it via a silent package-manager install. If that cleanup install fails, this warning is logged. The added package still works; only leftover temporary state may remain.

Source

Thrown at packages/angular/cli/src/commands/add/cli.ts:619

      const projectManifest = await this.getProjectManifest();
      if (projectManifest) {
        if (projectManifest.dependencies) {
          delete projectManifest.dependencies[packageName];
        }
        if (projectManifest.devDependencies) {
          delete projectManifest.devDependencies[packageName];
        }

        await fs.writeFile(
          join(this.context.root, 'package.json'),
          JSON.stringify(projectManifest, null, 2) + '\n',
        );
      }

      // 2. Silent install pass to prune files from node_modules and update the lockfile
      await this.context.packageManager.install({ ignoreScripts: true });
    } catch (error) {
      this.context.logger.warn(
        `Failed to clean up temporary dependency '${packageName}': ` +
          `${error instanceof Error ? error.message : error}`,
      );
    }
  }

  private async installPackageTask(
    context: AddCommandTaskContext,
    task: AddCommandTaskWrapper,
    options: Options<AddCommandArgs>,
  ): Promise<void> {
    const { registry } = options;
    const { packageIdentifier, savePackage } = context;
    const { packageManager } = this.context;

    // Only show if installation will actually occur
    task.title = 'Installing package';

View on GitHub (pinned to bb72145f9a)

Solutions

  1. Run the package manager install manually (`npm install`) to restore a consistent node_modules/lockfile.
  2. Check registry connectivity and proxy settings.
  3. Delete node_modules and the lockfile, then reinstall.
  4. Inspect package.json/lockfile for leftover temporary dependency entries and remove them.

Example fix

// before (manual cleanup fails silently)
// after
rm -rf node_modules package-lock.json && npm install
Defensive patterns

Strategy: retry

Validate before calling

const ok = await pm.install({ dryRun: true }); if (!ok) { await exec('npm install'); }

Type guard

function isErr(e: unknown): e is Error { return e instanceof Error; }

Try / catch

try { await pm.install({ ignoreScripts: true }); } catch (e) { logger.warn(`cleanup failed: ${e instanceof Error ? e.message : e}`); await exec('npm install'); }

Prevention

When it happens

Trigger: The silent `packageManager.install({ ignoreScripts: true })` inside cleanUpTemporaryDependency throws — e.g. corrupted lockfile, network/registry outage, or peer-dependency conflicts when pruning the temp dependency.

Common situations: Offline or flaky npm/yarn/pnpm/bun registry access; a package whose removal conflicts with existing peer dependencies; npm cache corruption; scripts disabled by a misconfigured .npmrc.

Related errors


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