angular/angular-cli · warning

Unable to update custom karma configuration file

Error message

Unable to update custom karma configuration file ("${karmaConfigFile}"). Reason: ${error.message}
References to the "@angular-devkit/build-angular" package within the file may need to be removed manually.

What it means

During the use-application-builder migration, custom karma.conf files are rewritten to drop references to @angular-devkit/build-angular. If rewriting (require() of the config or tree.overwrite) fails, this warning reports the reason and tells you the references may need manual removal.

Solutions

  1. Open the named karma config file and manually remove/replace references to @angular-devkit/build-angular (e.g. switch to @angular/build unit-test builder).
  2. Simplify the karma.conf (remove conditional/dynamic code) and re-run the migration.
  3. Convert exotic syntax (ESM/TS) in the config to plain CommonJS JS.
  4. Ensure the file is writable and not read-only.

Example fix

// before (karma.conf.js)
const { customKarma } = require('@angular-devkit/build-angular');
// after
module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine'] }); };
Defensive patterns

Strategy: try-catch

Validate before calling

const src = fs.readFileSync(karmaConfigFile, 'utf8'); if (src.includes('@angular-devkit/build-angular')) console.warn(`${karmaConfigFile} references build-angular; expect migration rewrite`);

Type guard

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

Try / catch

try { tree.overwrite(karmaConfigFile, updatedKarmaConfigText); } catch (error) { const reason = error instanceof Error ? `Reason: ${error.message}` : ''; logger.warn(`Unable to update custom karma configuration file ("${karmaConfigFile}"). ${reason}`); }

Prevention

When it happens

Trigger: The karma config transformation throws — e.g. the karma.conf.js uses syntax the transformer cannot handle, executes code at load time that throws, or the file cannot be parsed/written.

Common situations: Highly customized karma.conf.js with conditional logic, imports of local modules, or ES module syntax where CJS is expected; karma.conf TypeScript variants; files with unusual encodings.

Related errors


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

Appendix: source

Thrown at packages/schematics/angular/migrations/use-application-builder/migration.ts:326

          continue;
        }

        try {
          const originalKarmaConfigText = tree.readText(karmaConfigFile);
          const updatedKarmaConfigText = originalKarmaConfigText
            .replaceAll(`require('@angular-devkit/build-angular/plugins/karma'),`, '')
            .replaceAll(`require('@angular-devkit/build-angular/plugins/karma')`, '');

          if (updatedKarmaConfigText.includes('@angular-devkit/build-angular/plugins')) {
            throw new Error(
              'Migration does not support found usage of "@angular-devkit/build-angular".',
            );
          } else {
            tree.overwrite(karmaConfigFile, updatedKarmaConfigText);
          }
        } catch (error) {
          const reason = error instanceof Error ? `Reason: ${error.message}` : '';
          context.logger.warn(
            `Unable to update custom karma configuration file ("${karmaConfigFile}"). ` +
              reason +
              '\nReferences to the "@angular-devkit/build-angular" package within the file may need to be removed manually.',
          );
        }
      }
    }

    return chain(rules);
  });
}

function deleteFile(path: string): Rule {
  return (tree) => {
    tree.delete(path);
  };
}

View on GitHub (pinned to bb72145f9a)