{"record":{"id":"759969d59d25e671","repo":"laurent22/joplin","slug":"notes-can-only-be-created-within-a-notebook","errorCode":null,"errorMessage":"Notes can only be created within a notebook.","messagePattern":"Notes can only be created within a notebook\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/app-cli/app/command-mknote.ts","lineNumber":17,"sourceCode":"import BaseCommand from './base-command';\nimport app from './app';\nimport { _ } from '@joplin/lib/locale';\nimport Note from '@joplin/lib/models/Note';\nimport { NoteEntity } from '@joplin/lib/services/database/types';\n\nclass Command extends BaseCommand {\n\tpublic override usage() {\n\t\treturn 'mknote <new-note>';\n\t}\n\n\tpublic override description() {\n\t\treturn _('Creates a new note.');\n\t}\n\n\tpublic override async action(args: { 'new-note': string }) {\n\t\tif (!app().currentFolder()) throw new Error(_('Notes can only be created within a notebook.'));\n\n\t\tlet note: NoteEntity = {\n\t\t\ttitle: args['new-note'],\n\t\t\tparent_id: app().currentFolder().id,\n\t\t};\n\n\t\tnote = await Note.save(note);\n\t\tvoid Note.updateGeolocation(note.id);\n\n\t\tapp().switchCurrentFolder(app().currentFolder());\n\t}\n}\n\nmodule.exports = Command;\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/laurent22/joplin/blob/2654b33620775080d1d59c552259d41e33dad3d2/packages/app-cli/app/command-mknote.ts#L1-L32","documentation":"Thrown by `mknote <new-note>` when `app().currentFolder()` is falsy. Unlike `edit` (which can auto-create a note and prompts), mknote has no notebook fallback and refuses to create a note without a parent. The note's `parent_id` would otherwise be unset.","triggerScenarios":"Running `joplin mknote <title>` with no notebook selected; on a fresh profile; after deleting all notebooks; when `activeFolderId` points to a deleted folder.","commonSituations":"First-run usage; scripted note creation that didn't first ensure a notebook; profile reset.","solutions":["Create and select a notebook first: `joplin mkbook MyNotes && joplin use MyNotes`","In scripts, pre-check `joplin ls /` output or `Setting.value('activeFolderId')` before invoking mknote","If migrating, import into a default notebook instead of creating notes one-by-one"],"exampleFix":"// before\njoplin mknote \"Idea\"   // throws: Notes can only be created within a notebook.\n\n// after\njoplin mkbook Inbox\njoplin use Inbox\njoplin mknote \"Idea\"","handlingStrategy":"validation","validationCode":"import app from './app';\n\nfunction assertNotebookForCreate(): void {\n  if (!app().currentFolder()) {\n    throw new Error('No active notebook. Run `mkbook <name>` then `use <name>` before mknote.');\n  }\n}","typeGuard":"const isActiveNotebook = (f: any): f is { id: string } =>\n  f !== null && typeof f.id === 'string';","tryCatchPattern":null,"preventionTips":["Wrap bulk `mknote` calls in a precondition check on `currentFolder()`","Seed profiles with a default notebook in setup scripts","Use `mkbook` + `use` before any note-creation command"],"tags":["cli","mknote","notebook","precondition"],"backgroundTag":null,"analyzedSha":"2654b33620775080d1d59c552259d41e33dad3d2","analyzedAt":"2026-08-12T14:26:46.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}