{"record":{"id":"96462d00e105eafb","repo":"n8n-io/n8n","slug":"version-flags-version-not-found-for-workflow","errorCode":null,"errorMessage":"Version \"${flags.version}\" not found for workflow \"${workflows[0].name}\" (${workflows[0].id})","messagePattern":"Version \"(.+?)\" not found for workflow \"(.+?)\" \\((.+?)\\)","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/export/workflow.ts","lineNumber":141,"sourceCode":"\t\t\twhere: this.getWhereFilter(flags),\n\t\t\trelations: ['tags', 'shared', 'shared.project'],\n\t\t});\n\n\t\tif (workflows.length === 0) {\n\t\t\tthrow new UserError('No workflows found with specified filters');\n\t\t}\n\n\t\tconst workflowsToExport = await getWorkflowsToExport(workflows, flags);\n\n\t\tif (flags.published && workflowsToExport.length === 0) {\n\t\t\tif (flags.id)\n\t\t\t\tthrow new UserError(\n\t\t\t\t\t`No published version found for workflow \"${workflows[0].name}\" (${workflows[0].id})`,\n\t\t\t\t);\n\t\t\telse throw new UserError('No workflows with published versions found.');\n\t\t}\n\t\tif (flags.version && flags.id && workflowsToExport.length === 0) {\n\t\t\tthrow new UserError(\n\t\t\t\t`Version \"${flags.version}\" not found for workflow \"${workflows[0].name}\" (${workflows[0].id})`,\n\t\t\t);\n\t\t}\n\t\tif (workflowsToExport.length === 0) {\n\t\t\tthrow new UserError('No workflows found with specified filters');\n\t\t}\n\n\t\tif (flags.separate) {\n\t\t\tlet fileContents: string;\n\t\t\tlet i: number;\n\t\t\tfor (i = 0; i < workflowsToExport.length; i++) {\n\t\t\t\tfileContents = JSON.stringify(workflowsToExport[i], null, flags.pretty ? 2 : undefined);\n\t\t\t\tconst filename = `${\n\t\t\t\t\t(flags.output!.endsWith(path.sep) ? flags.output : flags.output + path.sep) +\n\t\t\t\t\tworkflowsToExport[i].id\n\t\t\t\t}.json`;\n\t\t\t\tfs.writeFileSync(filename, fileContents);\n\t\t\t}","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/cli/src/commands/export/workflow.ts#L123-L159","documentation":"Thrown by `export:workflow` when `--version` and `--id` are set, the workflow exists, but the specified version ID is not present in WorkflowHistoryRepository for that workflow. getWorkflowsToExport filters out the workflow because history lookup yields nothing.","triggerScenarios":"`n8n export:workflow --id=X --version=nonexistent-uuid`. The version ID does not match any `workflowId/versionId` pair in the history table.","commonSituations":"Typing or copying the version ID incorrectly; version belonged to a different workflow; history retention policy deleted old versions; cross-environment export where version IDs differ.","solutions":["List the workflow's versions from the history table to find a valid versionId.","Drop `--version` to export the current version.","Confirm the version belongs to this workflow: `SELECT * FROM workflow_history WHERE workflow_id=X`."],"exampleFix":"// before\nn8n export:workflow --id=X --version=abc-def\n// after — find valid versions first\n// SELECT version_id, saved_at FROM workflow_history WHERE workflow_id='X' ORDER BY saved_at DESC LIMIT 5;\nn8n export:workflow --id=X --version=<valid-version-id>","handlingStrategy":"validation","validationCode":"// Verify the version exists in history before exporting\nasync function versionExists(ds: DataSource, workflowId: string, versionId: string): Promise<boolean> {\n  return await ds.getRepository('workflow_history').exist({ where: { workflowId, versionId } });\n}\nif (!(await versionExists(ds, workflowId, versionId))) {\n  throw new Error(`Version ${versionId} not in history for workflow ${workflowId}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await execN8n(['export:workflow', '--id', id, '--version', vid]);\n} catch (e) {\n  if (e.message.startsWith('Version \"')) {\n    // list available versions and pick one\n  } else throw e;\n}","preventionTips":["Always look up versionId from workflow_history, never copy from another environment.","Confirm versionId belongs to the workflow: WHERE workflow_id = X AND version_id = Y."],"tags":["cli","export","workflow","version","history","user-error"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}