// guides · n8n error index

n8n Code node errors: "Code doesn't return items properly" and 10 more, fixed

The exact errors the n8n Code node throws, what each one means and the fix: return format, json not an object, Each Item vs All Items mode, fetch and axios, disallowed modules, and the empty-array trap. Tested on n8n 2.43.7.

Updated 2026-10-19 · about 10 minutes

Still stuck after these steps? Paste your exact n8n error and we'll reproduce it and email you the fix, free →

Steps

  1. Check the mode first

    Open the Code node and look at Mode. Run Once for All Items gives you every incoming item in $input.all() and expects an array back. Run Once for Each Item runs your code once per item, gives you $json (or $input.item.json) and expects one object back. Most Code node errors come from writing code for one mode while the node is set to the other.

  2. Return items in the shape n8n wants

    Each item is an object with a json key that holds an object: { json: { name: 'Ada', total: 42 } }. In All Items mode return an array of those; in Each Item mode return just one. Strings, numbers, null, nested arrays and json: 'text' all fail.

  3. Read the error message

    The message names the problem and, with [item 0] or [line 1], where it happened. Match it against the table below: each row is a real error from a test run, with the fix.

  4. Swap fetch and axios for this.helpers.httpRequest

    Inside the Code node, fetch isn't defined and require() is blocked unless the admin allows a module. await this.helpers.httpRequest({ url, json: true }) works out of the box. For anything bigger, use an HTTP Request node before the Code node instead.

  5. Test with the data you really get

    Click Execute step on the Code node and look at the input panel on the left: field names are case-sensitive, and a field that is text ("42") won't add up like a number. Use Number(...) or JSON.parse(...) where needed.

Copy-paste templates that work

Run Once for All Items (the default): you get every item at once and must return an array.

// Mode: Run Once for All Items
const out = [];
for (const item of $input.all()) {
  out.push({ json: { name: item.json.name, total: item.json.price * item.json.qty } });
}
return out; // always an array of { json: {...} }

Run Once for Each Item: the code runs once per item and returns one object.

// Mode: Run Once for Each Item
const j = $input.item.json; // or $json
return { json: { name: j.name, total: j.price * j.qty } }; // one object, not an array

Calling an API from the Code node: fetch and axios aren't available, but n8n's own helper is.

const data = await this.helpers.httpRequest({
  url: 'https://api.example.com/items',
  json: true,
});
return [{ json: data }];

Every error we got, and the fix

Code node failing with access to env vars denied or process is not defined [line 1]? Use $env and unblock it: see n8n access to env vars denied.

Code node failing with Node ran out of memory? That is the task runner cap, not your code: see n8n out of memory errors.

On 19 October 2026 we ran 23 small workflows in n8n 2.43.7 with n8n execute: a Manual Trigger, a Code node sending two items, the Code node under test, then an Edit Fields (Set) node to see whether the workflow carried on. These are the exact messages n8n printed.

What the code didError n8n showedFix
return 'hello';Code doesn't return items properlyReturn an array of objects, not a string or number.
No return at allCode doesn't return items properlyAdd return at the end of the code.
return [null]; or return [[{json:{...}}]];Code doesn't return items properlyOne flat array, one object per item.
return [{json: 'text'}];A 'json' property isn't an object [item 0]Put fields inside json: {json: {text: 'text'}}.
Each Item mode, return [{json:{...}}];A 'json' property isn't an object [item 0]In Each Item mode return one object, without the square brackets.
return [{json:{a:1}, binary:'x'}];A 'binary' property isn't an object [item 0]Leave binary out unless it holds real binary data.
$('Missing Node')Referenced node doesn't existUse the exact node name, including case and spaces. Renamed a node? Update the code.
require('axios')Module 'axios' is disallowed [line 1]Use this.helpers.httpRequest, or allow the module on self-hosted n8n.
require('crypto')Module 'crypto' is disallowed [line 1]Set NODE_FUNCTION_ALLOW_BUILTIN=crypto For an HMAC or a hash you may not need code at all: see the n8n Crypto node guide.and restart n8n.
await fetch(...)fetch is not defined [line 1]Use this.helpers.httpRequest (tested below).
JSON.parse('not json')Unexpected token 'o', "not json" is not valid JSON [line 1]The text isn't JSON. Check what the previous node really sent, or wrap it in try/catch.

For the three doesn't return items properly cases, n8n adds: Please return an array of objects, one for each item you would like to output. For the json cases it adds: In the returned data, every key named 'json' must point to an object.

Traps that don't show an error

Allowing modules (self-hosted n8n)

Parsing a model reply into JSON? The Structured Output Parser does it without code; its errors are in n8n Structured Output Parser not working.

What we tested, and what we didn't

$execution.customData.set() in a Code node ignores booleans and objects without an error; details in n8n Execution Data node not saving.

FAQ

What does "Code doesn't return items properly" mean in n8n?

Your Code node returned something that isn't a list of items: a string, a number, null, a nested array, or nothing at all because there's no return. Return an array of objects like [{ json: { ... } }].

How do I fix "A 'json' property isn't an object"?

Every json key must hold an object. Change { json: 'text' } to { json: { text: 'text' } }. In Run Once for Each Item mode, also return a single object rather than an array.

Why does my n8n workflow stop after the Code node with no error?

The Code node returned an empty array, so there were no items for the next node. Return at least one item, or turn on Always Output Data in the node's Settings.

Can I use fetch or axios in the n8n Code node?

Not by default: fetch is not defined and require('axios') is disallowed. Use await this.helpers.httpRequest({ url, json: true }), an HTTP Request node, or on self-hosted n8n allow the package with NODE_FUNCTION_ALLOW_EXTERNAL.

What's the difference between $input.all(), $input.item and $json?

$input.all() is every incoming item and belongs in Run Once for All Items mode. $input.item and $json are the current item in Run Once for Each Item mode. In All Items mode, $input.item quietly gives you only the first item.

Related guides

New guides

Still stuck on your n8n error?

Paste the exact error and say what the workflow should do. We reproduce it on a real n8n install and email you the fix or a working workflow, usually within 24h. Free while we're in beta.

We'll only email you about your error and TaskToAgent.