n8n-io/n8n · error · Error

.onFalse() is only available on IF nodes (${NODE_TYPES.IF})

Error message

.onFalse() is only available on IF nodes (${NODE_TYPES.IF})

What it means

Thrown by NodeInstanceImpl.onFalse() when isIfNodeType(this.type) is false. Symmetric to onTrue: the false-output branch builder only exists on n8n-nodes-base.if nodes; other node types lack that output port.

Source

Thrown at packages/@n8n/workflow-sdk/src/workflow-builder/node-builders/node-builder.ts:332

		if (!isIfNodeType(this.type)) {
			throw new Error(`.onTrue() is only available on IF nodes (${NODE_TYPES.IF})`);
		}
		const builder = new IfElseBuilderImpl<TOutput>(
			this as unknown as NodeInstance<'n8n-nodes-base.if', string, TOutput>,
		);
		return builder.onTrue(target);
	}

	/**
	 * Start building an IF branch with the false branch target.
	 * Only available on IF nodes (n8n-nodes-base.if).
	 *
	 * @example
	 * ifNode.onFalse(falseHandler).onTrue(trueHandler)
	 */
	onFalse(target: IfElseTarget): IfElseBuilder<TOutput> {
		if (!isIfNodeType(this.type)) {
			throw new Error(`.onFalse() is only available on IF nodes (${NODE_TYPES.IF})`);
		}
		const builder = new IfElseBuilderImpl<TOutput>(
			this as unknown as NodeInstance<'n8n-nodes-base.if', string, TOutput>,
		);
		return builder.onFalse(target);
	}

	/**
	 * Start building a Switch case with a case target.
	 * Only available on Switch nodes (n8n-nodes-base.switch).
	 *
	 * @example
	 * switchNode.onCase(0, caseA).onCase(1, caseB)
	 */
	onCase(index: number, target: SwitchCaseTarget): SwitchCaseBuilder<TOutput> {
		if (!isSwitchNodeType(this.type)) {
			throw new Error(`.onCase() is only available on Switch nodes (${NODE_TYPES.SWITCH})`);
		}

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Use node('n8n-nodes-base.if', ...) for the node you call .onFalse() on.
  2. For other node types, use the appropriate wiring (.to(), .onCase()).
  3. Narrow with isIfNodeType before invoking onTrue/onFalse.

Example fix

// before
const n = node('n8n-nodes-base.code', 'v2', { ... });
n.onFalse(fallback); // throws
// after
const ifNode = node('n8n-nodes-base.if', 'v1', { ... });
ifNode.onTrue(handler).onFalse(fallback);
Defensive patterns

Strategy: type-guard

Validate before calling

function assertIfNode(node: NodeInstance): asserts node is NodeInstance<'n8n-nodes-base.if', string, unknown> {
  if (node.type !== 'n8n-nodes-base.if') {
    throw new Error(`.onFalse() requires an IF node, got ${node.type}`);
  }
}

assertIfNode(myNode);
myNode.onFalse(handler);

Type guard

import { isIfNodeType } from '@n8n/workflow-sdk';

function isIfNode(node: NodeInstance): node is NodeInstance<'n8n-nodes-base.if', string, unknown> {
  return isIfNodeType(node.type);
}

Prevention

When it happens

Trigger: Calling someNode.onFalse(handler) on a non-IF node; assuming every node has a 'false' branch.

Common situations: Mis-typed node factory call; using a Switch node where an IF was intended; generic branch-building code.

Related errors


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