OrchardCMS/OrchardCore · error · TypeError
Invalid attempt to destructure non-iterable instance. In…
Error message
Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.
What it means
Babel's compiled array destructuring helper (_slicedToArray -> _nonIterableRest, bundled into vuedraggable.common.js) throws this TypeError when destructuring a value that is neither an array nor iterable (no [Symbol.iterator]) — after _toArray's fallbacks (Object/Map/Set/Arguments/TypedArray) all fail to produce an array-like.
Solutions
- Guard the source before destructuring: `const arr = Array.isArray(x) ? x : [];` then destructure.
- For array-like objects (arguments, NodeLists, HTMLCollections), convert first with Array.from(x) before destructuring.
- Trace which destructure site throws via the stack into vuedraggable's compiled code and fix the producing function to always return an array.
- For Map/Set-like values ensure they are actually Map/Set (the helper only converts when constructor.name matches); coerce explicitly.
- Fix the model passed to draggable components (e.g. v-model / list prop) so it is always an array, initializing empty lists instead of null.
Example fix
// before const [first, second] = getData(); // getData() may return undefined // after const data = getData(); const [first, second] = Array.isArray(data) ? data : [];
Defensive patterns
Strategy: type-guard
Validate before calling
if (!Array.isArray(value) && !(value && typeof value[Symbol.iterator] === 'function')) { throw new TypeError('Expected iterable/array for destructuring, got: ' + Object.prototype.toString.call(value)); } Type guard
function isIterable(v) { return v != null && typeof v[Symbol.iterator] === 'function'; } Try / catch
try { const [a, b] = value; } catch (e) { if (e instanceof TypeError && /non-iterable|iterable/.test(e.message)) { const [a, b] = Array.from(value ?? []); } else { throw e; } } Prevention
- Default to arrays before destructuring: `const [a] = x || []`
- Convert array-likes (NodeList, arguments, HTMLCollection) with Array.from first
- Ensure draggable v-model/list props are always initialized arrays, never null
- Make helpers that feed destructuring always return arrays (early returns included)
- Enable lint rules (prefer-const + no-unused-vars won't catch it; add runtime guards in dev builds) to catch null-returning producers early
When it happens
Trigger: Transpiled code doing `const [a, b] = x` where x is undefined/null, a plain non-iterable object, a number, or a DOM/foreign collection without Symbol.iterator — e.g. destructuring a result of a function that returned null, or an HTMLFormControlsCollection/old NodeList in an environment lacking iterable support patched around.
Common situations: Calling a helper that returns undefined on early exit and destructuring its result; JSON-parsed data assumed to be arrays but actually objects/null; using vuedraggable with a value/model that is not an array (dragging a non-list value); browser without Symbol.iterator for a specific collection type while Babel helpers assume iterability.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Invalid attempt to destructure non-iterable instance. In…
- @@toPrimitive must return a primitive value.
- @@toPrimitive must return a primitive value.
- @@toPrimitive must return a primitive value.
- Invalid attempt to spread non-iterable instance. In order…
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/77570a34cdc3d1db.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.Resources/wwwroot/Vendor/vue-draggable-2.24.3/vuedraggable.common.js:1870
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i];
}
return arr2;
}
// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/nonIterableRest.js
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
// EXTERNAL MODULE: ./node_modules/core-js/modules/es7.array.includes.js
var es7_array_includes = __webpack_require__("6762");
// EXTERNAL MODULE: ./node_modules/core-js/modules/es6.string.includes.js
var es6_string_includes = __webpack_require__("2fdb");
// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js
function _arrayWithoutHoles(arr) {View on GitHub (pinned to 4306c0717f)