hcengineering/platform · error · Error
Template meta not found: ${template.id}
Error message
Template meta not found: ${template.id} What it means
During importOrgSpace, templates are first processed by createDocTemplateMetaHierarhy which records { seqNumber, code } into templateMetaMap keyed by template id. Later, when creating attached docs, each template must have that meta entry; if it is missing the importer's internal invariant is broken and it throws this error.
Source
Thrown at packages/importer/src/importer/importer.ts:1063
if (this.isDocumentTemplate(doc)) {
await this.createDocTemplateMetaHierarhy(doc as ImportControlledDocumentTemplate, templateMetaMap, spaceId)
} else {
await this.createControlledDocMetaHierarhy(doc as ImportControlledDocument, templateMetaMap, spaceId)
}
}
// Partition templates and documents
const templateMap = new Map<Ref<ControlledDocument>, ImportControlledDocumentTemplate>()
const documentMap = new Map<Ref<ControlledDocument>, ImportControlledDocument>()
for (const doc of space.docs) {
this.partitionTemplatesFromDocuments(doc, documentMap, templateMap)
}
// Create attached docs for templates
for (const template of templateMap.values()) {
const meta = templateMetaMap.get(template.id)
if (meta === undefined) {
throw new Error('Template meta not found: ' + template.id)
}
await this.createDocTemplateAttachedDoc(template, meta.seqNumber, meta.code, spaceId)
}
// Create attached docs for documents
for (const document of documentMap.values()) {
await this.createControlledDocAttachedDoc(document, spaceId)
}
return spaceId
}
private partitionTemplatesFromDocuments (
doc: ImportControlledDocOrTemplate,
documentMap: Map<Ref<ControlledDocument>, ImportControlledDocument>,
templateMap: Map<Ref<ControlledDocument>, ImportControlledDocumentTemplate>
): void {
if (this.isDocumentTemplate(doc)) {View on GitHub (pinned to 63e28dc964)
Solutions
- Ensure createDocTemplateMetaHierarhy is invoked for every doc classified as a template, including templates nested under controlled documents.
- Check import data for duplicate doc.id values that collide in templateMetaMap and make ids unique.
- Verify each doc's class field correctly marks templates (documents.mixin.DocumentTemplate) so partitioning matches the meta pass.
- Add a validation pass before import that asserts every template in space.docs will be visited by the meta hierarchy traversal.
Example fix
// before
const meta = templateMetaMap.get(template.id)
if (meta === undefined) {
throw new Error('Template meta not found: ' + template.id)
}
// after
let meta = templateMetaMap.get(template.id)
if (meta === undefined) {
this.logger.warn('Template meta missing, computing lazily: ' + template.id)
await this.createDocTemplateMetaHierarhy(template, templateMetaMap, spaceId)
meta = templateMetaMap.get(template.id)
}
if (meta === undefined) {
throw new Error('Template meta not found: ' + template.id)
} Defensive patterns
Strategy: validation
Validate before calling
const templateIds = new Set<string>()
const collect = (d: ImportDoc): void => {
if (d.class === documents.mixin.DocumentTemplate) templateIds.add(d.id)
d.subdocs.forEach(collect)
}
space.docs.forEach(collect)
if (new Set(templateIds).size !== templateIds.size) throw new Error('Duplicate template ids in import payload') Type guard
function hasTemplateMeta(
map: Map<Ref<ControlledDocument>, { seqNumber: number, code: string }>,
id: Ref<ControlledDocument>
): boolean {
return map.has(id)
} Try / catch
try {
await importer.importOrgSpace(space)
} catch (err) {
if (err instanceof Error && err.message.startsWith('Template meta not found:')) {
const id = err.message.split(': ')[1]
// inspect import payload for that template: nesting/duplicate id issue
} else throw err
} Prevention
- Keep template ids unique across the whole import payload
- Ensure templates nested under controlled documents are still routed through the meta hierarchy pass
- Verify class fields (documents.mixin.DocumentTemplate) are set correctly in the import JSON
- Dry-run classification (partitionTemplatesFromDocuments) and cross-check against meta-map keys before committing
When it happens
Trigger: A template appears in templateMap (collected by partitionTemplatesFromDocuments over all docs and subdocs) but was never passed through createDocTemplateMetaHierarhy — e.g. a template nested under a document branch (createControlledDocMetaHierarhy) that does not recurse into template children, or a doc.id collision overwriting the map key.
Common situations: Import data where a DocumentTemplate is nested inside a non-template parent so the meta-hierarchy pass skips it; duplicated ids in the import payload causing templateMetaMap key mismatches; hand-edited import JSON with inconsistent class fields.
Related errors
- Project ${projectPath} not found
- Failed to create document template: ${template.title}
- Failed to create document template attached doc: ${template.
- update is null
- Parent not found: ${issue.clickupParentId} (for task: ${clic
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/9fbe9088eaa0214b.
Report an issue: GitHub.