{"record":{"id":"802ca8f39ff2a178","repo":"angular/angular","slug":"missing-proxyzonespec-802ca8","errorCode":null,"errorMessage":"Missing ProxyZoneSpec","messagePattern":"Missing ProxyZoneSpec","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/zone.js/lib/vitest/vitest.ts","lineNumber":61,"sourceCode":" */\nconst CURRIED_MODIFIER_NAMES = ['skipIf', 'runIf', 'each', 'for'] as const;\n\ntype TEST_MODIFIER_NAME = (typeof DIRECT_MODIFIER_NAMES | typeof CURRIED_MODIFIER_NAMES)[number];\n\nexport function patchVitest(Zone: ZoneType): void {\n  Zone.__load_patch('vitest', (context: any, Zone: TestingZoneType) => {\n    // Vitest global variable set by the Vitest runner during test execution\n    const vitestGlobal = context['vitest'] as {['__zone_patch__']?: boolean} | undefined;\n\n    // Skip patching if vitest is not present or has already been patched\n    if (typeof vitestGlobal === 'undefined' || vitestGlobal['__zone_patch__']) {\n      return;\n    }\n    vitestGlobal['__zone_patch__'] = true;\n\n    // Ensure other testing related Zone.js patches have been applied\n    if (!Zone.ProxyZoneSpec) {\n      throw new Error('Missing ProxyZoneSpec');\n    }\n    if (!Zone.SyncTestZoneSpec) {\n      throw new Error('Missing SyncTestZoneSpec');\n    }\n\n    // Setup testing related Zone instances\n    const rootZone = Zone.current;\n    const syncZone = rootZone.fork(new Zone.SyncTestZoneSpec('vitest.describe'));\n    const proxyZone = rootZone.fork(new Zone.ProxyZoneSpec());\n\n    /**\n     * Gets a function wrapping the body of a vitest `describe` block to execute in a\n     * synchronous-only zone.\n     */\n    function wrapDescribeInZone(describeBody: Function): Function {\n      // `describe` might be called without a body (e.g. `describe.todo`)\n      if (typeof describeBody !== 'function') {\n        return describeBody;","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/angular/angular/blob/51cb07e98081ab7e4e84a9e0949266a8e19cca84/packages/zone.js/lib/vitest/vitest.ts#L43-L79","documentation":"The vitest patch needs ProxyZoneSpec to create the proxy zone that isolates each vitest test's zone state. It checks Zone.ProxyZoneSpec right after marking vitest with __zone_patch__; if the proxy zone-spec module was never loaded, the property is undefined and it throws. Loading zone.js for vitest therefore requires the proxy spec to have been registered first.","triggerScenarios":"Setting up zone.js with vitest by loading only a vitest-specific patch file without 'zone.js/lib/zone-spec/proxy'; using a custom entry like zone-vitest.js that omits the proxy spec; importing the vitest patch before the proxy module. Fires only when global.vitest exists (inside a vitest run).","commonSituations":"Adopting vitest with Angular/zone-based code and hand-rolling the zone setup in vitest setupFiles instead of using the documented preset; partial migration where jest setup files are reused; tree-shaking or selective imports trimming the proxy spec out of the bundle.","solutions":["In vitest setupFiles, load the proxy spec before the vitest patch: import 'zone.js/lib/zone-spec/proxy' then 'zone.js/lib/vitest/vitest' (or the zone-testing equivalent that already contains it)","Prefer the documented Angular vitest setup which wires the correct zone.js bundles","After setup, assert (globalThis.Zone as any).ProxyZoneSpec is truthy in a smoke test"],"exampleFix":"// before (vitest.setup.ts)\nimport 'zone.js/lib/vitest/vitest'; // ProxyZoneSpec not yet registered\n\n// after\nimport 'zone.js/lib/zone-spec/proxy';\nimport 'zone.js/lib/zone-spec/sync-test';\nimport 'zone.js/lib/vitest/vitest';","handlingStrategy":"validation","validationCode":"// vitest setupFiles, ordered imports\nimport 'zone.js/lib/zone-spec/proxy';\nimport 'zone.js/lib/zone-spec/sync-test';\nimport 'zone.js/lib/vitest/vitest';\nif (!(globalThis.Zone as any).ProxyZoneSpec) throw new Error('proxy spec missing');","typeGuard":"const hasProxyZoneSpec = (z: any): boolean =>\n  typeof z?.ProxyZoneSpec === 'function';","tryCatchPattern":null,"preventionTips":["Use the documented Angular vitest zone preset instead of hand-rolled patch imports","Keep zone-related imports together at the top of a single setup file"],"tags":["zone-js","vitest","proxy-zone","test-setup"],"backgroundTag":"missing-zone-polyfill","analyzedSha":"51cb07e98081ab7e4e84a9e0949266a8e19cca84","analyzedAt":"2026-08-22T07:04:54.531Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}