laurent22/joplin · error · Error

Notes can only be created within a notebook.

Error message

Notes can only be created within a notebook.

What it means

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.

Source

Thrown at packages/app-cli/app/command-mknote.ts:17

import BaseCommand from './base-command';
import app from './app';
import { _ } from '@joplin/lib/locale';
import Note from '@joplin/lib/models/Note';
import { NoteEntity } from '@joplin/lib/services/database/types';

class Command extends BaseCommand {
	public override usage() {
		return 'mknote <new-note>';
	}

	public override description() {
		return _('Creates a new note.');
	}

	public override async action(args: { 'new-note': string }) {
		if (!app().currentFolder()) throw new Error(_('Notes can only be created within a notebook.'));

		let note: NoteEntity = {
			title: args['new-note'],
			parent_id: app().currentFolder().id,
		};

		note = await Note.save(note);
		void Note.updateGeolocation(note.id);

		app().switchCurrentFolder(app().currentFolder());
	}
}

module.exports = Command;

View on GitHub (pinned to 2654b33620)

Solutions

  1. Create and select a notebook first: `joplin mkbook MyNotes && joplin use MyNotes`
  2. In scripts, pre-check `joplin ls /` output or `Setting.value('activeFolderId')` before invoking mknote
  3. If migrating, import into a default notebook instead of creating notes one-by-one

Example fix

// before
joplin mknote "Idea"   // throws: Notes can only be created within a notebook.

// after
joplin mkbook Inbox
joplin use Inbox
joplin mknote "Idea"
Defensive patterns

Strategy: validation

Validate before calling

import app from './app';

function assertNotebookForCreate(): void {
  if (!app().currentFolder()) {
    throw new Error('No active notebook. Run `mkbook <name>` then `use <name>` before mknote.');
  }
}

Type guard

const isActiveNotebook = (f: any): f is { id: string } =>
  f !== null && typeof f.id === 'string';

Prevention

When it happens

Trigger: Running `joplin mknote <title>` with no notebook selected; on a fresh profile; after deleting all notebooks; when `activeFolderId` points to a deleted folder.

Common situations: First-run usage; scripted note creation that didn't first ensure a notebook; profile reset.

Related errors


AI-assisted analysis of laurent22/joplin@2654b33620 (2026-08-12). Data as JSON: /api/errors/759969d59d25e671. Report an issue: GitHub.