{"record":{"id":"974480301583162d","repo":"n8n-io/n8n","slug":"ontrue-is-only-available-on-if-nodes-node-ty","errorCode":null,"errorMessage":".onTrue() is only available on IF nodes (${NODE_TYPES.IF})","messagePattern":"\\.onTrue\\(\\) is only available on IF nodes \\((.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/workflow-sdk/src/workflow-builder/node-builders/node-builder.ts","lineNumber":315,"sourceCode":"\t */\n\toutput(index: number): OutputSelector<TType, TVersion, TOutput> {\n\t\treturn new OutputSelectorImpl(this, index) as unknown as OutputSelector<\n\t\t\tTType,\n\t\t\tTVersion,\n\t\t\tTOutput\n\t\t>;\n\t}\n\n\t/**\n\t * Start building an IF branch with the true branch target.\n\t * Only available on IF nodes (n8n-nodes-base.if).\n\t *\n\t * @example\n\t * ifNode.onTrue(trueHandler).onFalse(falseHandler)\n\t */\n\tonTrue(target: IfElseTarget): IfElseBuilder<TOutput> {\n\t\tif (!isIfNodeType(this.type)) {\n\t\t\tthrow new Error(`.onTrue() is only available on IF nodes (${NODE_TYPES.IF})`);\n\t\t}\n\t\tconst builder = new IfElseBuilderImpl<TOutput>(\n\t\t\tthis as unknown as NodeInstance<'n8n-nodes-base.if', string, TOutput>,\n\t\t);\n\t\treturn builder.onTrue(target);\n\t}\n\n\t/**\n\t * Start building an IF branch with the false branch target.\n\t * Only available on IF nodes (n8n-nodes-base.if).\n\t *\n\t * @example\n\t * ifNode.onFalse(falseHandler).onTrue(trueHandler)\n\t */\n\tonFalse(target: IfElseTarget): IfElseBuilder<TOutput> {\n\t\tif (!isIfNodeType(this.type)) {\n\t\t\tthrow new Error(`.onFalse() is only available on IF nodes (${NODE_TYPES.IF})`);\n\t\t}","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/workflow-sdk/src/workflow-builder/node-builders/node-builder.ts#L297-L333","documentation":"Thrown by NodeInstanceImpl.onTrue() when isIfNodeType(this.type) returns false. The .onTrue()/.onFalse() branch builders target the true/false output ports that only exist on n8n-nodes-base.if nodes; calling onTrue on any other node type is rejected because those ports do not exist.","triggerScenarios":"Calling someNode.onTrue(handler) where someNode is a Switch, Code, HTTP, Merge, or any non-IF node type. Passing a generic NodeInstance to a helper that unconditionally calls .onTrue().","commonSituations":"Wrong node type selected (e.g. used Switch instead of IF); copy-paste from an IF example onto another node; dynamic node construction where the type string is wrong.","solutions":["Create the node with type 'n8n-nodes-base.if' before calling .onTrue().","For Switch nodes use .onCase(index, target); for plain fan-out use .to().","Type-narrow with isIfNodeType before calling .onTrue()/.onFalse()."],"exampleFix":"// before\nconst n = node('n8n-nodes-base.switch', 'v1', { ... });\nn.onTrue(handler); // throws\n// after\nconst ifNode = node('n8n-nodes-base.if', 'v1', { ... });\nifNode.onTrue(handler).onFalse(otherHandler);","handlingStrategy":"type-guard","validationCode":"function assertIfNode(node: NodeInstance): asserts node is NodeInstance<'n8n-nodes-base.if', string, unknown> {\n  if (node.type !== 'n8n-nodes-base.if') {\n    throw new Error(`.onTrue() requires an IF node, got ${node.type}`);\n  }\n}\n\nassertIfNode(myNode);\nmyNode.onTrue(handler);","typeGuard":"import { isIfNodeType } from '@n8n/workflow-sdk';\n\nfunction isIfNode(node: NodeInstance): node is NodeInstance<'n8n-nodes-base.if', string, unknown> {\n  return isIfNodeType(node.type);\n}","tryCatchPattern":null,"preventionTips":["Create IF nodes explicitly with node('n8n-nodes-base.if', ...).","Narrow with isIfNodeType before calling .onTrue()/.onFalse().","Reserve .onTrue()/.onFalse() for IF nodes; use .onCase() for Switch and .to() for plain fan-out."],"tags":["runtime","builder","if-node","branching"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}