Summary
extract (with content) crashes when the source instance has singleton collections. The content extractor calls readItems() for every collection and spreads the response into an array, but a singleton returns a single object (not an array), so the spread throws:
Error: Spread syntax requires ...iterable[Symbol.iterator] to be a function
Context: {"collection":"globals","function":"getDataFromCollection"}
The crash is fatal and stops content extraction — no content is written for the singleton or for any collection alphabetically after it.
Steps to reproduce
- A Directus instance with at least one singleton collection (e.g. the Agency OS template's
globals, os_settings, pages_blog, pages_projects).
directus-template-cli extract -p --templateName="x" --templateLocation=./t (content enabled, the default).
- Crashes at the first singleton (
globals).
Cause
dist/lib/extract/extract-content.js → getCollectionItems:
const response = await api.client.request(readItems(collection, { limit: PAGE_SIZE, page }));
items.push(...response); // singleton response is an object, not iterable
if (response.length < PAGE_SIZE) break;
For a singleton, readItems(collection) resolves to the item object, so ...response (spread) and response.length are both invalid.
Suggested fix
Guard for non-array responses:
const response = await api.client.request(readItems(collection, { limit: PAGE_SIZE, page }));
const rows = Array.isArray(response) ? response : (response ? [response] : []);
items.push(...rows);
if (rows.length < PAGE_SIZE) break;
(Alternatively, detect singletons from the collection meta and use readSingleton.) Verified locally — patching this lets a full extract-with-content complete cleanly on an instance with the four singletons above.
Environment
- directus-template-cli 0.8.0
- Node 24, darwin-arm64
- Directus 11.17.2
Summary
extract(with content) crashes when the source instance has singleton collections. The content extractor callsreadItems()for every collection and spreads the response into an array, but a singleton returns a single object (not an array), so the spread throws:The crash is fatal and stops content extraction — no content is written for the singleton or for any collection alphabetically after it.
Steps to reproduce
globals,os_settings,pages_blog,pages_projects).directus-template-cli extract -p --templateName="x" --templateLocation=./t(content enabled, the default).globals).Cause
dist/lib/extract/extract-content.js→getCollectionItems:For a singleton,
readItems(collection)resolves to the item object, so...response(spread) andresponse.lengthare both invalid.Suggested fix
Guard for non-array responses:
(Alternatively, detect singletons from the collection meta and use
readSingleton.) Verified locally — patching this lets a full extract-with-content complete cleanly on an instance with the four singletons above.Environment