n8n-io/n8n · error · NodeOperationError
The node does not have a "Main" output set. Please add one.
Error message
The node does not have a "Main" output set. Please add one.
What it means
Thrown by the Code node when the node's configured outputs contain no output of type 'main'. The node's execute returns an array of item arrays; without a Main output wired, there is no slot to send the result to, so execution aborts after the code runs.
Source
Thrown at packages/@n8n/nodes-langchain/nodes/code/Code.node.ts:449
const mainOutputs: INodeOutputConfiguration[] = outputs.filter(
(output) => output.type === NodeConnectionTypes.Main,
);
const options = { multiOutput: mainOutputs.length !== 1 };
let items: INodeExecutionData[] | INodeExecutionData[][];
try {
items = await sandbox.runCodeAllItems(options);
} catch (error) {
if (!this.continueOnFail()) throw error;
items = [{ json: { error: (error as Error).message } }];
if (options.multiOutput) {
items = [items];
}
}
if (mainOutputs.length === 0) {
throw new NodeOperationError(
this.getNode(),
'The node does not have a "Main" output set. Please add one.',
{
itemIndex,
},
);
} else if (!options.multiOutput) {
for (const item of items as INodeExecutionData[]) {
standardizeOutput(item.json);
}
return [items as INodeExecutionData[]];
} else {
items.forEach((data) => {
for (const item of data as INodeExecutionData[]) {
standardizeOutput(item.json);
}
});
return items as INodeExecutionData[][];View on GitHub (pinned to 5ac6606e81)
Solutions
- Open the Code node's Outputs setting and add at least one output of type 'Main'.
- If using multiOutput mode, ensure each output is typed correctly and at least one is Main.
- Reset the node outputs to defaults via the node's menu if the config is corrupted.
Example fix
// before
if (mainOutputs.length === 0) {
throw new NodeOperationError(this.getNode(), 'The node does not have a "Main" output set. Please add one.', { itemIndex });
}
// after — describe how to add it
if (mainOutputs.length === 0) {
throw new NodeOperationError(this.getNode(), {
message: 'The node does not have a "Main" output set. Please add one.',
description: 'Open the node Outputs setting and add an output with type Main.',
itemIndex,
});
} Defensive patterns
Strategy: validation
Validate before calling
const outputs = ctx.getNodeOutputs();
const mainOutputs = outputs.filter((o) => o.type === 'main');
if (mainOutputs.length === 0) {
throw new Error('Add at least one Main output to the Code node');
} Type guard
function hasMainOutput(outputs: Array<{ type?: string }>): boolean {
return outputs.some((o) => o.type === 'main');
} Prevention
- Keep at least one Main output in the Code node's Outputs config.
- Reset outputs to defaults if the config is corrupted.
- Validate workflow imports include the outputs fixedCollection.
When it happens
Trigger: The Code node's 'Outputs' configuration has zero outputs with type 'main' (e.g. all outputs were removed, or only non-main outputs remain). The mainOutputs filter returns an empty array and the guard throws.
Common situations: User customized the node outputs (via the UI 'Outputs' editor) and deleted the default Main output; a workflow import omitted the outputs config; the outputs fixedCollection was edited to only contain AI/other types.
Related errors
- No code for "Execute" set on node "${this.getNode().name}
- The ‘text‘ parameter is empty.
- Invalid message type. Only imageBinary and imageUrl are supp
- No binary data set.
- The 'prompt' parameter is empty.
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/583a3d3ed4507368.
Report an issue: GitHub.