{"record":{"id":"ad94a4793472394e","repo":"n8n-io/n8n","slug":"filesystem-error-while-creating-the-output-directo","errorCode":null,"errorMessage":"Filesystem error while creating the output directory: ${e instanceof Error ? e.message : String(e)}","messagePattern":"Filesystem error while creating the output directory: (.+?)","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/export/workflow.ts","lineNumber":109,"sourceCode":"\t\tif (flags.separate) {\n\t\t\ttry {\n\t\t\t\tif (!flags.output) {\n\t\t\t\t\tthis.logger.info(\n\t\t\t\t\t\t'You must inform an output directory via --output when using --separate',\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (fs.existsSync(flags.output)) {\n\t\t\t\t\tif (!fs.lstatSync(flags.output).isDirectory()) {\n\t\t\t\t\t\tthis.logger.info('The parameter --output must be a directory');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfs.mkdirSync(flags.output, { recursive: true });\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tthrow new UserError(\n\t\t\t\t\t`Filesystem error while creating the output directory: ${e instanceof Error ? e.message : String(e)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (flags.output) {\n\t\t\tif (fs.existsSync(flags.output)) {\n\t\t\t\tif (fs.lstatSync(flags.output).isDirectory()) {\n\t\t\t\t\tthis.logger.info('The parameter --output must be a writeable file');\n\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) {","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/cli/src/commands/export/workflow.ts#L91-L127","documentation":"The `n8n export:workflow` command wraps filesystem mkdir/lstat errors while preparing the --output directory in a UserError. The original error message (or stringified value) is interpolated. Distinct from the 'must be a directory/file' soft warnings which only log and return.","triggerScenarios":"Passing --output pointing at a path the process cannot create or stat: permission denied, read-only filesystem, invalid characters, or a parent that doesn't exist and recursive mkdir fails.","commonSituations":"Output path on a volume without write permission; container with a read-only mount; path with a typo or missing parent dir; SELinux/AppArmor denying the write.","solutions":["Check the embedded cause in the message — fix permissions or choose a writable path.","Ensure the parent directory exists and is writable, or rely on recursive:true by giving a valid absolute path.","If running in Docker, mount a writable volume at the output location."],"exampleFix":"# before\nn8n export:workflow --all --output=/readonly/workflows\n\n# after\nn8n export:workflow --all --output=./workflows  # writable dir","handlingStrategy":"validation","validationCode":"import { access, constants } from 'node:fs/promises';\nimport { dirname } from 'node:path';\ntry {\n  await access(dirname(outputPath), constants.W_OK);\n} catch { /* path not writable: choose another output dir */ }","typeGuard":"function isOutputDirError(error: unknown): boolean {\n  return error instanceof Error && error.message.startsWith('Filesystem error while creating the output directory');\n}","tryCatchPattern":"try {\n  await ExportWorkflow.run(argv);\n} catch (e) {\n  if (isOutputDirError(e)) { /* parse embedded cause, fix permissions/path, retry */ }\n  else throw e;\n}","preventionTips":["Pre-validate the output path is writable before running the export.","Use absolute paths on mounted, writable volumes in containers.","Avoid read-only filesystems or paths with invalid characters."],"tags":["cli","export","filesystem","user-error"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}