{"record":{"id":"99742e4d02d9de6c","repo":"ReactiveX/rxjs","slug":"cannot-initialize-rxjs-observable-polyfill-and-co","errorCode":null,"errorMessage":"Cannot initialize @rxjs/observable-polyfill and could not fully restore the realm","messagePattern":"Cannot initialize @rxjs/observable-polyfill and could not fully restore the realm","errorType":"exception","errorClass":"AggregateError","httpStatus":null,"severity":"critical","filePath":"packages/observable-polyfill/src/index.ts","lineNumber":1368,"sourceCode":"      applied.push(installation);\n    }\n  } catch (error) {\n    const rollbackErrors: unknown[] = [];\n    for (let index = applied.length - 1; index >= 0; index--) {\n      const installation = applied[index]!;\n      try {\n        if (installation.previous) {\n          Object.defineProperty(installation.target, installation.key, installation.previous);\n        } else {\n          Reflect.deleteProperty(installation.target, installation.key);\n        }\n      } catch (rollbackError) {\n        rollbackErrors.push(rollbackError);\n      }\n    }\n\n    if (rollbackErrors.length > 0) {\n      throw new AggregateError(\n        [error, ...rollbackErrors],\n        'Cannot initialize @rxjs/observable-polyfill and could not fully restore the realm'\n      );\n    }\n    throw error;\n  }\n}\n\nfunction initializeObservablePolyfill(): void {\n  const installations: PropertyInstallation[] = [];\n  const activeObservable = (globalThis as typeof globalThis & { Observable?: ObservableCtor }).Observable;\n\n  if (activeObservable === undefined) {\n    const AbortControllerCtor = globalThis.AbortController;\n    const abortDescriptor = AbortControllerCtor && Object.getOwnPropertyDescriptor(AbortControllerCtor.prototype, 'abort');\n    if (!AbortControllerCtor || !abortDescriptor || typeof abortDescriptor.value !== 'function') {\n      throw new TypeError('Cannot initialize @rxjs/observable-polyfill: AbortController.prototype.abort is unavailable');\n    }","sourceCodeStart":1350,"sourceCodeEnd":1386,"githubUrl":"https://github.com/ReactiveX/rxjs/blob/54796b38a57e6309f9861e174737479bb3f63f61/packages/observable-polyfill/src/index.ts#L1350-L1386","documentation":"Thrown when installing the @rxjs/observable-polyfill failed and the subsequent rollback of already-applied patches also failed, so the realm is left partially patched. The library aggregates the original error plus all rollback errors into one AggregateError so nothing is silently swallowed.","triggerScenarios":"Importing or calling install() of @rxjs/observable-polyfill in an environment where Observable is missing and either AbortController patching or a later installation step throws, and one of the already-installed property installations cannot be removed during rollback (e.g. frozen prototypes, non-configurable properties, or a second polyfill racing).","commonSituations":"Test realms or sandboxes with sealed/frozen globals, two polyfills installing simultaneously, hostile environments (SSR frameworks freezing globalThis), or partial platform shims that define non-configurable descriptors.","solutions":["Inspect error.errors array: the first element is the root installation failure, the rest are rollback failures — fix the root cause first","Ensure globalThis.AbortController exists with a prototype-level abort method before importing the polyfill","Ensure Observable/AbortController prototype properties are configurable and not frozen (delete Object.freeze on globalThis or its prototypes)","Ensure only one polyfill installation runs (no concurrent import of a competing Observable polyfill)"],"exampleFix":"// before\nimport '@rxjs/observable-polyfill'; // throws AggregateError in frozen realm\n// after\nif (!globalThis.Observable) {\n  Object.getOwnPropertyDescriptor(AbortController.prototype, 'abort'); // sanity check\n  import('@rxjs/observable-polyfill');\n}","handlingStrategy":"try-catch","validationCode":"const abortOk = typeof globalThis.AbortController === 'function' &&\n  typeof Object.getOwnPropertyDescriptor(AbortController.prototype, 'abort')?.value === 'function';\nif (!globalThis.Observable && !abortOk) throw new Error('Polyfill prerequisites missing');","typeGuard":null,"tryCatchPattern":"try {\n  await import('@rxjs/observable-polyfill');\n} catch (e) {\n  if (e instanceof AggregateError) {\n    console.error('root cause:', e.errors[0]);\n    // realm is partially patched: reload/restart the realm rather than continuing\n  }\n  throw e;\n}","preventionTips":["Check AbortController and Observable descriptors before importing the polyfill","Never freeze globalThis or Observable/AbortController prototypes","Run polyfill installation once, at application entry, before any concurrent imports"],"tags":["polyfill","installation","rollback","aggregate-error","globalthis"],"backgroundTag":"polyfill-installation-failed","analyzedSha":"54796b38a57e6309f9861e174737479bb3f63f61","analyzedAt":"2026-08-28T10:21:27.410Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}