microsoft/TypeScript · error · TypeError

Symbol.asyncIterator is not defined.

Error message

Symbol.asyncIterator is not defined.

What it means

`__asyncGenerator` downlevels async generator functions for pre-ES2018 targets. It checks `Symbol.asyncIterator` and throws if it's missing, because the async-iteration protocol cannot operate without that well-known symbol.

Source

Thrown at src/compiler/factory/emitHelpers.ts:853

            };`,
};

const awaitHelper: UnscopedEmitHelper = {
    name: "typescript:await",
    importName: "__await",
    scoped: false,
    text: `
            var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }`,
};

const asyncGeneratorHelper: UnscopedEmitHelper = {
    name: "typescript:asyncGenerator",
    importName: "__asyncGenerator",
    scoped: false,
    dependencies: [awaitHelper],
    text: `
        var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
            if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
            var g = generator.apply(thisArg, _arguments || []), i, q = [];
            return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
            function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
            function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
            function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
            function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
            function fulfill(value) { resume("next", value); }
            function reject(value) { resume("throw", value); }
            function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
        };`,
};

const asyncDelegator: UnscopedEmitHelper = {
    name: "typescript:asyncDelegator",
    importName: "__asyncDelegator",
    scoped: false,
    dependencies: [awaitHelper],
    text: `

View on GitHub (pinned to b465fdbfe1)

Solutions

  1. Raise `target` to ES2018 or higher so TypeScript no longer emits this helper.
  2. Load a polyfill that defines Symbol.asyncIterator (e.g. core-js) before the compiled code runs.
  3. Bump the runtime (Node >= 10) to one with native Symbol.asyncIterator.

Example fix

// before
tsconfig: "target": "es2015"  // emits __asyncGenerator, throws on old runtimes

// after
tsconfig: "target": "es2018"  // native async iterators, no helper
// or, at runtime before app code:
require("core-js/features/symbol/async-iterator");
Defensive patterns

Strategy: validation

Validate before calling

// Detect the missing symbol before relying on async generators.
if (typeof Symbol === "undefined" || !(Symbol as any).asyncIterator) {
  throw new Error("Symbol.asyncIterator missing; load a polyfill or raise tsconfig target to es2018+.");
}

Type guard

function hasAsyncIterator(): boolean {
  return typeof Symbol !== "undefined" && !!(Symbol as unknown as { asyncIterator?: symbol }).asyncIterator;
}

Prevention

When it happens

Trigger: Running the emitted code on a runtime without Symbol.asyncIterator (Node < 10, old browsers) and with no polyfill loaded.

Common situations: tsconfig `target` set to ES2015/ES2017 while running on an older runtime; shipping compiled output to legacy browsers without polyfills.

Related errors


AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12). Data as JSON: /api/errors/fd2d0dccd9fde795. Report an issue: GitHub.