{"record":{"id":"f0e3ac92486e6bb4","repo":"n8n-io/n8n","slug":"file-does-not-seem-to-contain-valid-workflows","errorCode":null,"errorMessage":"File does not seem to contain valid workflows.","messagePattern":"File does not seem to contain valid workflows\\.","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/import/workflow.ts","lineNumber":34,"sourceCode":"import { z } from 'zod';\n\nimport { UM_FIX_INSTRUCTION } from '@/constants';\nimport { EventService } from '@/events/event.service';\nimport type { IWorkflowToImport, IWorkflowWithVersionMetadata } from '@/interfaces';\nimport { ImportService } from '@/services/import.service';\n\nimport { BaseCommand } from '../base-command';\n\nfunction assertHasWorkflowsToImport(\n\tworkflows: unknown[],\n): asserts workflows is IWorkflowToImport[] {\n\tfor (const workflow of workflows) {\n\t\tif (\n\t\t\ttypeof workflow !== 'object' ||\n\t\t\t!Object.prototype.hasOwnProperty.call(workflow, 'nodes') ||\n\t\t\t!Object.prototype.hasOwnProperty.call(workflow, 'connections')\n\t\t) {\n\t\t\tthrow new UserError('File does not seem to contain valid workflows.');\n\t\t}\n\t}\n}\n\n/**\n * Creates workflow entities from plain objects while preserving versionMetadata metadata.\n */\nfunction createWorkflowsWithVersionMetadata(\n\tworkflowRepository: WorkflowRepository,\n\tworkflows: IWorkflowToImport[],\n): IWorkflowWithVersionMetadata[] {\n\tconst createdWorkflows = workflowRepository.create(workflows);\n\treturn createdWorkflows.map((created, index) => ({\n\t\t...created,\n\t\tversionMetadata: workflows[index].versionMetadata,\n\t}));\n}\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/cli/src/commands/import/workflow.ts#L16-L52","documentation":"Thrown by assertHasWorkflowsToImport when any element of the parsed workflow array is not an object, or is missing the required `nodes` or `connections` properties. The type assertion guard (workflow.ts:25-37) validates workflow file shape before entity creation.","triggerScenarios":"Importing a JSON file (single or `--separate`) whose contents lack `nodes` and/or `connections` keys, or contain a non-object entry (e.g. a string or number in the array). Fires from readWorkflows for both single-file and per-file modes (though per-file mode catches and warns, line 278-281, instead of throwing).","commonSituations":"Using a credential export file as a workflow import; partial/corrupt export; hand-crafted JSON missing the connections field; wrong file passed to --input.","solutions":["Ensure each workflow object has `nodes` (array) and `connections` (object) keys — the two required fields.","Open the JSON in an editor and verify the shape matches a workflow export.","If using --separate, invalid files are skipped with a warning; check the log for 'Skipping invalid workflow file'."],"exampleFix":"// before — missing connections\n{ \"name\": \"My WF\", \"nodes\": [...] }\n// after\n{ \"name\": \"My WF\", \"nodes\": [...], \"connections\": {} }","handlingStrategy":"type-guard","validationCode":"function isValidWorkflowImport(w: unknown): w is { nodes: unknown; connections: unknown } {\n  return typeof w === 'object' && w !== null &&\n    Object.prototype.hasOwnProperty.call(w, 'nodes') &&\n    Object.prototype.hasOwnProperty.call(w, 'connections');\n}\nfunction validateWorkflows(arr: unknown[]) {\n  for (const w of arr) if (!isValidWorkflowImport(w)) {\n    throw new Error('Each entry must have nodes and connections');\n  }\n}\nvalidateWorkflows(parsedArray);","typeGuard":"function isWorkflowImport(w: unknown): w is { nodes: unknown[]; connections: Record<string, unknown> } {\n  return typeof w === 'object' && w !== null &&\n    'nodes' in w && 'connections' in w;\n}","tryCatchPattern":null,"preventionTips":["Validate workflow JSON shape before import — each entry needs `nodes` and `connections`.","Use --separate mode so a single bad file is skipped, not fatal.","Confirm you are importing a workflow export, not a credential export."],"tags":["cli","import","workflow","file-format","validation","type-guard","user-error"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}