microsoft/TypeScript · error · TypeError
Symbol.iterator is not defined.
Error message
Symbol.iterator is not defined.
What it means
`__values` throws this variant when `Symbol` itself (or Symbol.iterator) is missing from the runtime entirely — a pre-ES2015 environment without a polyfill. The helper distinguishes it from "Object is not iterable." by checking whether `Symbol.iterator` exists.
Source
Thrown at src/compiler/factory/emitHelpers.ts:1047
};
// ES2015 Destructuring Helpers
const valuesHelper: UnscopedEmitHelper = {
name: "typescript:values",
importName: "__values",
scoped: false,
text: `
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};`,
};
// ES2015 Generator Helpers
// The __generator helper is used by down-level transformations to emulate the runtime
// semantics of an ES2015 generator function. When called, this helper returns an
// object that implements the Iterator protocol, in that it has `next`, `return`, and
// `throw` methods that step through the generator when invoked.
//
// parameters:
// @param thisArg The value to use as the `this` binding for the transformed generator body.
// @param body A function that acts as the transformed generator body.
//
// variables:
// _ Persistent state for the generator that is shared between the helper and the
// generator body. The state object has the following members:
// sent() - A method that returns or throws the current completion value.
View on GitHub (pinned to b465fdbfe1)
Solutions
- Load a Symbol polyfill (e.g. core-js/es6/symbol) before the compiled code runs.
- Raise `target` to ES2015+ so the helper isn't emitted.
- Run on a runtime that ships Symbol natively.
Example fix
// before
tsconfig: "target": "es5", "lib": ["es5"] // old runtime -> "Symbol.iterator is not defined."
// after
require("core-js/es6/symbol"); // polyfill first
// or raise target:
// tsconfig: "target": "es2015" Defensive patterns
Strategy: validation
Validate before calling
if (typeof Symbol === "undefined" || !(Symbol as any).iterator) {
throw new Error("Symbol.iterator missing; load core-js es6.symbol polyfill or raise target to es2015+.");
} Type guard
function hasSymbolIterator(): boolean {
return typeof Symbol !== "undefined" && !!(Symbol as unknown as { iterator?: symbol }).iterator;
} Prevention
- Load a Symbol polyfill before any iterable code when targeting ES5.
- Raise tsconfig target to ES2015+ to drop __values.
- Document runtime requirements for ES5 builds.
When it happens
Trigger: Running ES5-targeted TS output on a runtime with no Symbol (old IE, very old Node, embedded JS engines) and no polyfill loaded.
Common situations: target: ES5 with no lib/polyfill; shipping to legacy embedded JS engines.
Related errors
- Symbol.asyncIterator is not defined.
- Object is not iterable.
- Symbol.asyncDispose is not defined.
- Symbol.dispose is not defined.
- Function expected
AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12).
Data as JSON: /api/errors/16c0c4c64b5d4b81.
Report an issue: GitHub.