{"record":{"id":"583a3d3ed4507368","repo":"n8n-io/n8n","slug":"the-node-does-not-have-a-main-output-set-please","errorCode":null,"errorMessage":"The node does not have a \"Main\" output set. Please add one.","messagePattern":"The node does not have a \"Main\" output set\\. Please add one\\.","errorType":"exception","errorClass":"NodeOperationError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/code/Code.node.ts","lineNumber":449,"sourceCode":"\t\tconst mainOutputs: INodeOutputConfiguration[] = outputs.filter(\n\t\t\t(output) => output.type === NodeConnectionTypes.Main,\n\t\t);\n\n\t\tconst options = { multiOutput: mainOutputs.length !== 1 };\n\n\t\tlet items: INodeExecutionData[] | INodeExecutionData[][];\n\t\ttry {\n\t\t\titems = await sandbox.runCodeAllItems(options);\n\t\t} catch (error) {\n\t\t\tif (!this.continueOnFail()) throw error;\n\t\t\titems = [{ json: { error: (error as Error).message } }];\n\t\t\tif (options.multiOutput) {\n\t\t\t\titems = [items];\n\t\t\t}\n\t\t}\n\n\t\tif (mainOutputs.length === 0) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'The node does not have a \"Main\" output set. Please add one.',\n\t\t\t\t{\n\t\t\t\t\titemIndex,\n\t\t\t\t},\n\t\t\t);\n\t\t} else if (!options.multiOutput) {\n\t\t\tfor (const item of items as INodeExecutionData[]) {\n\t\t\t\tstandardizeOutput(item.json);\n\t\t\t}\n\t\t\treturn [items as INodeExecutionData[]];\n\t\t} else {\n\t\t\titems.forEach((data) => {\n\t\t\t\tfor (const item of data as INodeExecutionData[]) {\n\t\t\t\t\tstandardizeOutput(item.json);\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn items as INodeExecutionData[][];","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/code/Code.node.ts#L431-L467","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nif (mainOutputs.length === 0) {\n  throw new NodeOperationError(this.getNode(), 'The node does not have a \"Main\" output set. Please add one.', { itemIndex });\n}\n\n// after — describe how to add it\nif (mainOutputs.length === 0) {\n  throw new NodeOperationError(this.getNode(), {\n    message: 'The node does not have a \"Main\" output set. Please add one.',\n    description: 'Open the node Outputs setting and add an output with type Main.',\n    itemIndex,\n  });\n}","handlingStrategy":"validation","validationCode":"const outputs = ctx.getNodeOutputs();\nconst mainOutputs = outputs.filter((o) => o.type === 'main');\nif (mainOutputs.length === 0) {\n  throw new Error('Add at least one Main output to the Code node');\n}","typeGuard":"function hasMainOutput(outputs: Array<{ type?: string }>): boolean {\n  return outputs.some((o) => o.type === 'main');\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["configuration","code-node","outputs","parameter-validation"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}