n8n-io/n8n · warning · Error

File too large: ${stat.size} bytes (max ${MAX_FILE_SIZE} byt

Error message

File too large: ${stat.size} bytes (max ${MAX_FILE_SIZE} bytes). Use write_file to replace the entire content.

What it means

Thrown by the edit_file tool when the target file's size exceeds MAX_FILE_SIZE (1,048,576 bytes = 1 MB, defined in constants.ts). The guard runs after resolving the path but before reading the file content, preventing large files from being loaded into memory. The message suggests using write_file to replace the entire content instead.

Source

Thrown at packages/@n8n/computer-use/src/tools/filesystem/edit-file.ts:33

export const editFileTool: ToolDefinition<typeof inputSchema> = {
	name: 'edit_file',
	description:
		'Apply a targeted search-and-replace to a file. Replaces the first occurrence of oldString with newString. Fails if oldString is not found.',
	inputSchema,
	annotations: {},
	async getAffectedResources({ filePath }, { dir }) {
		return [
			await buildFilesystemResource(dir, filePath, 'filesystemRead', `Read file: ${filePath}`),
			await buildFilesystemResource(dir, filePath, 'filesystemWrite', `Edit file: ${filePath}`),
		];
	},
	async execute({ filePath, oldString, newString }, { dir }) {
		const resolvedReadablePath = await resolveReadablePath(dir, filePath);
		const resolvedWritablePath = await resolveSafePath(dir, filePath);

		const stat = await fs.stat(resolvedReadablePath);
		if (stat.size > MAX_FILE_SIZE) {
			throw new Error(
				`File too large: ${stat.size} bytes (max ${MAX_FILE_SIZE} bytes). Use write_file to replace the entire content.`,
			);
		}

		const content = await fs.readFile(resolvedReadablePath, 'utf-8');

		if (!content.includes(oldString)) {
			throw new Error(`oldString not found in file: ${filePath}`);
		}

		await fs.writeFile(resolvedWritablePath, content.replace(oldString, newString), 'utf-8');

		return formatCallToolResult({ path: filePath });
	},
};

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Use write_file to replace the entire file content instead of editing in place
  2. Use search_files to locate the specific content, then write_file with the full updated content
  3. Split the large file into smaller modules if ongoing edits are needed

Example fix

// before (edit_file fails on a large file):
await edit_file({ filePath: 'large-bundle.js', oldString: 'foo', newString: 'bar' });

// after (use write_file for full replacement):
const content = await read_file({ filePath: 'large-bundle.js' });
await write_file({ filePath: 'large-bundle.js', content: content.replace('foo', 'bar') });
Defensive patterns

Strategy: validation

Validate before calling

import * as fs from 'node:fs/promises';
import { MAX_FILE_SIZE } from './constants';

async function canEditFile(filePath: string): Promise<boolean> {
  const stat = await fs.stat(filePath);
  return stat.size <= MAX_FILE_SIZE;
}

// Before calling edit_file:
if (!(await canEditFile(resolvedPath))) {
  // Use write_file instead
  const content = await fs.readFile(resolvedPath, 'utf-8');
  await write_file({ filePath, content: content.replace(oldStr, newStr) });
}

Type guard

function isFileTooLargeError(e: unknown): boolean {
  return e instanceof Error && e.message.startsWith('File too large:') && e.message.includes('Use write_file');
}

Prevention

When it happens

Trigger: Calling edit_file on a file larger than 1 MB — a large data file (JSON/CSV export), a minified JavaScript bundle, a log file, or a large generated source file.

Common situations: Agent attempts to edit a large generated file, a minified production bundle, a data export, or a compiled output.

Related errors


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