{"record":{"id":"02eeeaccc2feb7dc","repo":"n8n-io/n8n","slug":"no-published-version-found-for-workflow-workflo","errorCode":null,"errorMessage":"No published version found for workflow \"${workflows[0].name}\" (${workflows[0].id})","messagePattern":"No published version found for workflow \"(.+?)\" \\((.+?)\\)","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/export/workflow.ts","lineNumber":135,"sourceCode":"\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst workflows = await Container.get(WorkflowRepository).find({\n\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);","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/cli/src/commands/export/workflow.ts#L117-L153","documentation":"Thrown by `export:workflow` when `--published` and `--id` are set, the workflow exists, but `getWorkflowsToExport` returns empty — i.e. the workflow's `activeVersionId` has no matching row in WorkflowHistoryRepository (workflow.ts:215-228). The published/active version record is missing.","triggerScenarios":"`n8n export:workflow --id=X --published` on a workflow that was never activated, was deactivated, or whose workflow_history rows were pruned/migrated away. `getTargetVersionId` returns `workflow.activeVersionId ?? null`; if null or absent from history, the workflow is filtered out at mergeHistoriesIntoWorkflows (workflow.ts:259).","commonSituations":"Exporting a draft workflow that has never been published; workflow history feature disabled or history table cleaned; upgrading from an n8n version that did not track activeVersionId; running against a workflow imported without its history.","solutions":["Drop `--published` to export the current working version instead of the published one.","Activate/publish the workflow in the UI first so an activeVersionId is set and history is recorded.","Check `SELECT active_version_id FROM workflow_entity WHERE id=X` — if NULL, the workflow has no published version.","If history rows are missing, re-run with `--version=<some-version-id>` for a version that exists, or omit version flags entirely."],"exampleFix":"// before\nn8n export:workflow --id=X --published\n// after — export current version instead\nn8n export:workflow --id=X","handlingStrategy":"validation","validationCode":"// Confirm the workflow has a published (active) version before exporting\nasync function hasPublishedVersion(ds: DataSource, id: string): Promise<boolean> {\n  const row = await ds.getRepository('workflow_entity').findOne({ where: { id }, select: ['activeVersionId'] });\n  return Boolean(row?.activeVersionId);\n}\nif (!(await hasPublishedVersion(ds, id))) {\n  console.error('No published version — falling back to current version');\n  flags.published = false;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await execN8n(['export:workflow', '--id', id, '--published']);\n} catch (e) {\n  if (e.message.startsWith('No published version')) {\n    // fall back to current version\n    await execN8n(['export:workflow', '--id', id]);\n  } else throw e;\n}","preventionTips":["Activate workflows in the UI before exporting their published version.","Verify activeVersionId is set in the workflow_entity row before scripting --published exports.","Keep workflow history enabled so versions are recorded."],"tags":["cli","export","workflow","published","history","user-error"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}