angular/angular-cli · warning
Failed to automatically update types in "${tsConfigPath}". P
Error message
Failed to automatically update types in "${tsConfigPath}". Please manually remove "jasmine" and add "vitest/globals" to compilerOptions.types. What it means
The Karma-to-Vitest migration tries to rewrite compilerOptions.types in the project's tsconfig (remove "jasmine", add "vitest/globals") using a JSON editor. If editing fails (parse error, missing/odd tsconfig structure), it warns with manual instructions instead of failing the migration.
Source
Thrown at packages/schematics/angular/migrations/migrate-karma-to-vitest/migration.ts:164
if (tree.exists(tsConfigPath)) {
try {
const json = new JSONFile(tree, tsConfigPath);
const typesPath = ['compilerOptions', 'types'];
const existingTypes = (json.get(typesPath) as string[] | undefined) ?? [];
const newTypes = existingTypes.filter((t) => t !== 'jasmine');
if (!newTypes.includes('vitest/globals')) {
newTypes.push('vitest/globals');
}
if (
newTypes.length !== existingTypes.length ||
newTypes.some((t, i) => t !== existingTypes[i])
) {
json.modify(typesPath, newTypes);
}
} catch (err) {
context.logger.warn(
`Failed to automatically update types in "${tsConfigPath}". ` +
`Please manually remove "jasmine" and add "vitest/globals" to compilerOptions.types.`,
);
}
}
}
}
function logSummary(
context: SchematicContext,
migratedProjects: string[],
skippedNonApplications: string[],
skippedMissingAppBuilder: string[],
manualMigrationFiles: string[],
): void {
context.logger.info('\n--- Karma to Vitest Migration Summary ---');
context.logger.info(`Projects migrated: ${migratedProjects.length}`);
if (migratedProjects.length > 0) {View on GitHub (pinned to bb72145f9a)
Solutions
- Open the reported tsConfigPath and manually remove "jasmine" and add "vitest/globals" to compilerOptions.types.
- Fix JSON syntax errors in the tsconfig and re-run the migration.
- Verify file write permissions on the tsconfig.
- Ensure the tsconfig used by the test target is the one being edited (check extends chains).
Example fix
// before
class { "compilerOptions": { "types": ["jasmine"] } }
// after
"compilerOptions": { "types": ["vitest/globals"] } Defensive patterns
Strategy: try-catch
Validate before calling
let parsed; try { parsed = JSON.parse(stripComments(fs.readFileSync(tsConfigPath, 'utf8'))); } catch { console.warn(`${tsConfigPath} is not parseable — fix manually`); } Type guard
function isTsConfigWithTypes(v: unknown): v is { compilerOptions?: { types?: string[] } } { return typeof v === 'object' && v !== null && 'compilerOptions' in v; } Try / catch
try { json.modify(typesPath, newTypes); } catch { context.logger.warn(`Failed to automatically update types in "${tsConfigPath}". Please manually remove "jasmine" and add "vitest/globals".`); } Prevention
- Keep tsconfig files valid JSON(C) without exotic syntax.
- Ensure compilerOptions.types exists explicitly in the tsconfig used by tests.
- Don't make tsconfig read-only before running migrations.
- Review extends chains so the right tsconfig is edited.
When it happens
Trigger: `json.modify(typesPath, newTypes)` throws because the tsconfig file has JSON syntax errors (comments/trailing commas with strict parsing), is unreadable, or the types path cannot be created/modified in an unusual config layout.
Common situations: tsconfig extended/generated with unusual formats; hand-edited tsconfig with syntax errors; read-only files; a tsconfig whose compilerOptions.types is nested in an unexpected way.
Related errors
- Cannot update project "${projectName}" to use the applicatio
- Project "${options.project}" is configured to use Karma. Ple
- Unable to update custom karma configuration file ("${karmaCo
- Project "${projectName}" uses the "kjhtml" reporter. This ha
- Project "${projectName}" uses a custom Karma reporter "${r}"
AI-assisted analysis of angular/angular-cli@bb72145f9a (2026-08-30).
Data as JSON: /api/errors/59544119c78aff5b.
Report an issue: GitHub.