n8n-io/n8n · error

File "${input.path}" is not loaded.

Error message

File "${input.path}" is not loaded.

What it means

In the batch-str-replace-file tool, after readFile populates a TextEditorDocument and executeBatch runs, getText() should return the edited string. If it returns null, the document has no loaded text — an internal invariant of TextEditorDocument that should not be reachable given initialText was just set from the file content. The throw is a defensive guard against a regression that would otherwise write `null` to the file.

Source

Thrown at packages/@n8n/agents/src/workspace/tools/batch-str-replace-file.ts:75

		)
		.input(inputSchema)
		.output(outputSchema)
		.handler(async (input, ctx) => {
			try {
				const content = await filesystem.readFile(input.path, {
					encoding: 'utf-8',
					abortSignal: ctx.abortSignal,
				});
				const editor = new TextEditorDocument({ initialText: content.toString() });
				const result = editor.executeBatch(input.replacements);

				if (isBatchReplaceResult(result)) {
					return { success: false, error: 'Batch replacement failed.', results: result };
				}

				const editedContent = editor.getText();
				if (editedContent === null) {
					throw new Error(`File "${input.path}" is not loaded.`);
				}

				await filesystem.writeFile(input.path, editedContent, {
					overwrite: true,
					abortSignal: ctx.abortSignal,
				});
				return { success: true, result };
			} catch (error) {
				if (isAbortError(error)) throw error;
				return createErrorOutput(error);
			}
		})
		.build();
}

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Treat this as an internal bug — file an issue against @n8n/agents with the input path and replacements.
  2. Retry the operation on a fresh TextEditorDocument instance.
  3. As a workaround, use the single str_replace tool instead of the batch variant.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  return await batchStrReplace(...);
} catch (e) {
  if (e instanceof Error && /is not loaded/.test(e.message)) {
    // internal invariant — retry on a fresh editor, or fall back to single str_replace
  } else throw e;
}

Prevention

When it happens

Trigger: Effectively unreachable in normal flow (initialText is set from content right before). Would fire only if TextEditorDocument's internal text state was cleared by executeBatch (e.g. a future refactor resets the buffer) or if a subclass overrode behavior to null the document.

Common situations: A bug/regression in TextEditorDocument where executeBatch mutates state such that getText() returns null; concurrent reuse of the same editor instance; future code change that clears initialText.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/bfd1c0cef7d64606. Report an issue: GitHub.