siyuan-note/siyuan · error
--id is required
Error message
--id is required
What it means
The `export md` cobra subcommand requires the --id flag identifying the document to export as Markdown. The handler returns this error when --id is empty, before the dry-run check and before calling model.ExportMarkdownContent. The --output flag is optional (omit it to print to stdout).
Source
Thrown at kernel/cli/cmd/export.go:39
"os"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/spf13/cobra"
)
var exportCmd = &cobra.Command{
Use: "export",
Short: "Export documents",
}
var exportMdCmd = &cobra.Command{
Use: "md --id <id>",
Short: "Export as Markdown",
RunE: func(cmd *cobra.Command, args []string) error {
id, _ := cmd.Flags().GetString("id")
if id == "" {
return fmt.Errorf("--id is required")
}
output, _ := cmd.Flags().GetString("output")
if dryRun && output != "" {
fmt.Printf("[dry-run] Would export markdown for document %s to %s\n", id, output)
return nil
}
_, content := model.ExportMarkdownContent(id, 4, 0, true, false, false, false, false)
if output != "" {
return os.WriteFile(output, []byte(content), 0644)
}
fmt.Print(content)
return nil
},
}
var exportHTMLCmd = &cobra.Command{View on GitHub (pinned to 251596fc0d)
Solutions
- Supply the document ID: `siyuan export md --id <id>`.
- Optionally add `--output file.md` to write to a file instead of stdout.
- Look up the ID via `document list` or `document search`.
- Guard the ID variable in scripts.
- Verify the flag with `siyuan export md --help`.
Example fix
// before siyuan export md --output notes.md // after siyuan export md --id 20240101000000-abc1234 --output notes.md
Defensive patterns
Strategy: validation
Validate before calling
[ -n "$DOC_ID" ] || { echo '--id is required' >&2; exit 2; }
siyuan export md --id "$DOC_ID" --output "$OUT" Try / catch
if ! siyuan export md --id "$DOC_ID" --output "$OUT" 2>err.txt; then grep -q 'id is required' err.txt && echo "pass --id <docId>" >&2 exit 1 fi
Prevention
- Resolve the ID via list/search before exporting.
- Use `set -u`.
- Omit --output to stream to stdout for quick checks.
When it happens
Trigger: Running `siyuan export md` with no flags; passing `--id ""`; scripting with an unset ID variable; misspelling the flag; passing only --output.
Common situations: Forgetting the ID; copy-paste leaving a placeholder; shell variable empty for an iteration; assuming export of the whole notebook (not supported by this subcommand); confusing notebook ID with document ID.
Related errors
- --notebook is required
- --title is required
- --id is required
- --id and --notebook are required
- --output is required for docx
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/22f8a23584ef70ae.
Report an issue: GitHub.