{"record":{"id":"035855963955db45","repo":"angular/angular-cli","slug":"unable-to-update-custom-karma-configuration-file","errorCode":null,"errorMessage":"Unable to update custom karma configuration file (\"${karmaConfigFile}\"). Reason: ${error.message}\nReferences to the \"@angular-devkit/build-angular\" package within the file may need to be removed manually.","messagePattern":"Unable to update custom karma configuration file \\(\"(.+?)\"\\)\\. Reason: (.+?)\nReferences to the \"@angular-devkit/build-angular\" package within the file may need to be removed manually\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/schematics/angular/migrations/use-application-builder/migration.ts","lineNumber":326,"sourceCode":"          continue;\n        }\n\n        try {\n          const originalKarmaConfigText = tree.readText(karmaConfigFile);\n          const updatedKarmaConfigText = originalKarmaConfigText\n            .replaceAll(`require('@angular-devkit/build-angular/plugins/karma'),`, '')\n            .replaceAll(`require('@angular-devkit/build-angular/plugins/karma')`, '');\n\n          if (updatedKarmaConfigText.includes('@angular-devkit/build-angular/plugins')) {\n            throw new Error(\n              'Migration does not support found usage of \"@angular-devkit/build-angular\".',\n            );\n          } else {\n            tree.overwrite(karmaConfigFile, updatedKarmaConfigText);\n          }\n        } catch (error) {\n          const reason = error instanceof Error ? `Reason: ${error.message}` : '';\n          context.logger.warn(\n            `Unable to update custom karma configuration file (\"${karmaConfigFile}\"). ` +\n              reason +\n              '\\nReferences to the \"@angular-devkit/build-angular\" package within the file may need to be removed manually.',\n          );\n        }\n      }\n    }\n\n    return chain(rules);\n  });\n}\n\nfunction deleteFile(path: string): Rule {\n  return (tree) => {\n    tree.delete(path);\n  };\n}\n","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/migrations/use-application-builder/migration.ts#L308-L344","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","Simplify the karma.conf (remove conditional/dynamic code) and re-run the migration.","Convert exotic syntax (ESM/TS) in the config to plain CommonJS JS.","Ensure the file is writable and not read-only."],"exampleFix":"// before (karma.conf.js)\nconst { customKarma } = require('@angular-devkit/build-angular');\n// after\nmodule.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine'] }); };","handlingStrategy":"try-catch","validationCode":"const src = fs.readFileSync(karmaConfigFile, 'utf8'); if (src.includes('@angular-devkit/build-angular')) console.warn(`${karmaConfigFile} references build-angular; expect migration rewrite`);","typeGuard":"function isErrorWithMessage(e: unknown): e is Error { return e instanceof Error; }","tryCatchPattern":"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}`); }","preventionTips":["Keep karma.conf.js simple, synchronous CommonJS.","Avoid dynamic requires/conditionals in karma config.","Ensure config files are writable before migrating.","Plan to move to the @angular/build unit-test builder to drop karma configs entirely."],"tags":["karma","migration","application-builder","manual-intervention"],"backgroundTag":"karma-config-migration-failed","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}