<p><img class="alignnone size-full wp-image-4373" src="https://flowgenius.in/wp-content/uploads/2026/01/Child-5-Cluster-9.png" alt="" /></p>
<p style="text-align: center;">Step by Step Guide to Fix n8n Function Node Syntax Errors</p>
<p> </p>
<hr />
<p style="margin-bottom: 2em; line-height: 1.9;"><strong>Who this is for:</strong> Workflow developers who receive “Unexpected token” or “Missing ) after argument list” errors in n8n’s Function node and need a fast, reliable way to locate and fix them. <strong>We cover this in detail in the</strong> <a href="https://flowgenius.in/n8n-node-errors-troubleshooting/">n8n Node Specific Errors Guide.</a></p>
<div style="margin: 50px 0;">
<hr />
</div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">Quick Diagnosis</h2>
<blockquote style="margin: 0 0 2em 0; padding-left: 1em; border-left: 4px solid #e0e0e0;">
<p style="margin: 0; line-height: 1.9;"><strong>Problem:</strong> “Unexpected token” or “Missing ) after argument list” errors appear when a Function node runs.</p>
<p style="margin: 0; line-height: 1.9;"><strong>Quick fix:</strong> Open the Function node → enable <strong>“Show line numbers”</strong> → locate the highlighted line → correct the JavaScript syntax (e.g., close brackets, add missing commas, use proper <code>await</code>/<code>return</code>).</p>
<p style="margin: 0; line-height: 1.9;"><strong>One‑click test:</strong> Click <strong>“Execute Node”</strong> after fixing; the node should return a green checkmark and the expected output.</p>
</blockquote>
<div style="margin: 50px 0;">
<hr />
</div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">1. Why Function‑Node Syntax Errors Occur in n8n</h2>
<p><strong>If you encounter any</strong> <a href="/n8n-set-node-type-mismatch">n8n set node type mismatch</a><strong> resolve them before continuing with the setup.</strong></p>
<table style="border-collapse: collapse; width: 100%; margin-bottom: 2em;">
<thead>
<tr>
<th style="padding: 12px; text-align: left; border-bottom: 1px solid #e0e0e0;">Root Cause</th>
<th style="padding: 12px; text-align: left; border-bottom: 1px solid #e0e0e0;">Typical Error Message</th>
<th style="padding: 12px; text-align: left; border-bottom: 1px solid #e0e0e0;">Example</th>
</tr>
</thead>
<tbody>
<tr>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Missing/extra punctuation (<code>;</code> <code>,</code> <code>( ) { }</code>)</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">SyntaxError: Unexpected token <code>)</code></td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;"><code>return { foo: bar }</code> (missing comma)</td>
</tr>
<tr>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Wrong use of <code>await</code>/<code>async</code></td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">SyntaxError: Unexpected identifier</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;"><code>await $http.get(...)</code> inside a non‑async function</td>
</tr>
<tr>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Variable scope misuse (<code>$json</code>, <code>$item</code>, <code>$node</code>)</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">ReferenceError: <code>$json</code> is not defined</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;"><code>return $json.id</code> in a node that only has <code>$item</code></td>
</tr>
<tr>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Reserved word collision (e.g., <code>class</code>, <code>function</code>)</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">SyntaxError: Unexpected token ‘class’</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;"><code>const class = "test"</code></td>
</tr>
<tr>
<td style="padding: 12px;">Incorrect string interpolation</td>
<td style="padding: 12px;">SyntaxError: Unexpected token <code>`</code></td>
<td style="padding: 12px;"><code>return `User ${user.id}`</code> (missing back‑ticks)</td>
</tr>
</tbody>
</table>
<p style="margin-bottom: 2em; line-height: 1.9;">n8n’s Function node runs <strong>pure JavaScript (Node.js v18)</strong> in a sandbox. Any syntax that the Node runtime can’t parse aborts the node before the workflow continues.</p>
<div style="margin: 50px 0;">
<hr />
</div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">2. Enable Precise Debugging Tools</h2>
<p><strong>If you encounter any</strong> <a href="/n8n-merge-node-type-mismatch">n8n merge node type mismatch</a><strong> resolve them before continuing with the setup.</strong></p>
<p style="margin-bottom: 2em; line-height: 1.9;">Turn on visual aids that point you directly to the offending line.</p>
<ul style="margin-bottom: 2em; line-height: 1.9; list-style-type: disc; padding-left: 1.5em;">
<li><strong>Show line numbers</strong> – Click the gear icon ► <em>Editor Settings</em> ► toggle “Show line numbers”.</li>
<li><strong>Activate linting</strong> – In the same settings panel, enable “ESLint”. n8n underlines syntax problems in real time.</li>
<li><strong>Use the “Execute Node” button</strong> – Runs only the Function node, returning the exact error stack and the line number.</li>
</ul>
<blockquote style="margin: 0 0 2em 0; padding-left: 1em; border-left: 4px solid #e0e0e0;">
<p style="margin: 0; line-height: 1.9;"><strong>EEFA Note:</strong> In production workflows, never leave <code>console.log</code> statements that output sensitive data. Use <code>$node["Debug"].json</code> only in a dedicated debugging sub‑workflow.</p>
</blockquote>
<div style="margin: 50px 0;">
<hr />
</div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">3. Step‑by‑Step Workflow to Identify & Fix the Error</h2>
<table style="border-collapse: collapse; width: 100%; margin-bottom: 2em;">
<thead>
<tr>
<th style="padding: 12px; text-align: left; border-bottom: 1px solid #e0e0e0;">Step</th>
<th style="padding: 12px; text-align: left; border-bottom: 1px solid #e0e0e0;">Action</th>
<th style="padding: 12px; text-align: left; border-bottom: 1px solid #e0e0e0;">Expected Result</th>
</tr>
</thead>
<tbody>
<tr>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;"><b>1</b></td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Open the failing Function node.</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Code editor appears.</td>
</tr>
<tr>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;"><b>2</b></td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Click <strong>Execute Node</strong> (no input needed).</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Error panel shows <em>line X</em> and <em>error message</em>.</td>
</tr>
<tr>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;"><b>3</b></td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Jump to the highlighted line (line numbers now visible).</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Cursor lands on the offending token.</td>
</tr>
<tr>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;"><b>4</b></td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Apply the appropriate fix (see tables below).</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">No red underline; linting passes.</td>
</tr>
<tr>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;"><b>5</b></td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Re‑run <strong>Execute Node</strong>.</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Green checkmark + JSON output.</td>
</tr>
<tr>
<td style="padding: 12px;"><b>6</b></td>
<td style="padding: 12px;">Save the node and <strong>run the full workflow</strong> to confirm downstream nodes work.</td>
<td style="padding: 12px;">Workflow completes without errors.</td>
</tr>
</tbody>
</table>
<div style="margin: 50px 0;">
<hr />
</div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">4. Common Syntax Mistakes & Exact Fixes</h2>
<p><strong>If you encounter any </strong><a href="/n8n-function-node-reference-error">n8n function node reference error </a><strong>resolve them before continuing.</strong></p>
<h3 style="margin-bottom: 45px; line-height: 1.3;">4.1 Missing Comma or Bracket</h3>
<p style="margin-bottom: 2em; line-height: 1.9;"><strong>Problem:</strong> Objects need commas between properties and matching braces.</p>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; line-height: 1.9; overflow: auto;">// ❌ Bad – missing comma and trailing brace
return {
id: item.id
name: item.name,
</pre>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; line-height: 1.9; overflow: auto;">// ✅ Fixed – commas added, brace closed
return {
id: item.id,
name: item.name,
};
</pre>
<div style="margin: 30px 0;"></div>
<h3 style="margin-bottom: 45px; line-height: 1.3;">4.2 Improper <code>await</code> Usage</h3>
<p style="margin-bottom: 2em; line-height: 1.9;"><strong>Problem:</strong> <code>await</code> can only be used inside an <code>async</code> function.</p>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; line-height: 1.9; overflow: auto;">// ❌ Bad – node is not async
await $http.get('https://api.example.com');
</pre>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; line-height: 1.9; overflow: auto;">// ✅ Fixed – wrap code in an async IIFE
return (async () => {
const response = await $http.get('https://api.example.com');
return response.json;
})();
</pre>
<div style="margin: 30px 0;"></div>
<h3 style="margin-bottom: 45px; line-height: 1.3;">4.3 Wrong Variable Scope</h3>
<p style="margin-bottom: 2em; line-height: 1.9;"><strong>Problem:</strong> <code>$json</code> is unavailable in a “Function Item” node; use <code>$item</code> instead.</p>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; line-height: 1.9; overflow: auto;">// ❌ Bad – $json undefined here
return $json.id;
</pre>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; line-height: 1.9; overflow: auto;">// ✅ Fixed – reference the current item
return $item.json.id;
</pre>
<div style="margin: 30px 0;"></div>
<h3 style="margin-bottom: 45px; line-height: 1.3;">4.4 Reserved Word Collision</h3>
<p style="margin-bottom: 2em; line-height: 1.9;"><strong>Problem:</strong> JavaScript reserves words like <code>class</code>.</p>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; line-height: 1.9; overflow: auto;">// ❌ Bad – syntax error
const class = "premium";
</pre>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; line-height: 1.9; overflow: auto;">// ✅ Fixed – rename variable
const userClass = "premium";
</pre>
<div style="margin: 30px 0;"></div>
<h3 style="margin-bottom: 45px; line-height: 1.3;">4.5 Bad Template Literals</h3>
<p style="margin-bottom: 2em; line-height: 1.9;"><strong>Problem:</strong> Use back‑ticks for interpolation, not double quotes.</p>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; line-height: 1.9; overflow: auto;">// ❌ Bad – no interpolation
return "User ID: ${item.id}";
</pre>
<pre style="background: #fafafa; padding: 20px; border: 1px solid #e0e0e0; line-height: 1.9; overflow: auto;">// ✅ Fixed – back‑ticks enable ${}
return `User ID: ${item.id}`;
</pre>
<div style="margin: 50px 0;">
<hr />
</div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">5. Advanced Debugging Techniques</h2>
<p style="margin-bottom: 2em; line-height: 1.9;">*When simple fixes aren’t enough, these patterns help you capture runtime issues.*</p>
<table style="border-collapse: collapse; width: 100%; margin-bottom: 2em;">
<thead>
<tr>
<th style="padding: 12px; text-align: left; border-bottom: 1px solid #e0e0e0;">Technique</th>
<th style="padding: 12px; text-align: left; border-bottom: 1px solid #e0e0e0;">How‑to</th>
<th style="padding: 12px; text-align: left; border-bottom: 1px solid #e0e0e0;">When to Use</th>
</tr>
</thead>
<tbody>
<tr>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;"><strong>try / catch wrapper</strong></td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">
<pre style="margin: 0; background: none; padding: 0; border: none;">try { /* your logic */ } catch (e) { return { error: e.message }; }</pre>
</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">To capture runtime errors that aren’t syntax‑related.</td>
</tr>
<tr>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;"><strong>$node[“<NodeName>”].json inspection</strong></td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">
<pre style="margin: 0; background: none; padding: 0; border: none;">return $node["HTTP Request"].json;</pre>
</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">When you need to verify the exact payload from a previous node.</td>
</tr>
<tr>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;"><strong>console.error with process.env.NODE_ENV guard</strong></td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">
<pre style="margin: 0; background: none; padding: 0; border: none;">if (process.env.NODE_ENV !== 'production') console.error(e);</pre>
</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Prevents leaking errors in production logs.</td>
</tr>
<tr>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;"><strong>Unit‑test snippet in the editor</strong></td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">
<pre style="margin: 0; background: none; padding: 0; border: none;">// Simulate input\nconst $item = { json: { id: 1 } };\n// Your code here</pre>
</td>
<td style="padding: 12px; border-bottom: 1px solid #e0e0e0;">Quickly test logic without running the whole workflow.</td>
</tr>
</tbody>
</table>
<blockquote style="margin: 0 0 2em 0; padding-left: 1em; border-left: 4px solid #e0e0e0;">
<p style="margin: 0; line-height: 1.9;"><strong>EEFA Warning:</strong> The sandbox strips <code>require</code>, <code>process</code>, and other Node core modules. Attempting to import them will throw a “Cannot find module” error, which appears as a syntax error but is actually a security restriction.</p>
</blockquote>
<div style="margin: 50px 0;">
<hr />
</div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">6. Production‑Ready Checklist for Function Nodes</h2>
<ul style="margin-bottom: 2em; line-height: 1.9; list-style-type: disc; padding-left: 1.5em;">
<li>Linting enabled – no red squiggles before saving.</li>
<li><code>async</code> only when needed – avoid unnecessary promises.</li>
<li>No hard‑coded secrets – use n8n credentials or environment variables.</li>
<li>Error handling – wrap external calls in <code>try / catch</code>.</li>
<li>Output validation – ensure the returned object matches downstream expectations (<code>return { json: {...} }</code> vs. plain object).</li>
<li>Remove debug <code>console.log</code> – replace with <code>$node["Debug"].json</code> in a separate test workflow.</li>
</ul>
<div style="margin: 50px 0;">
<hr />
</div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">7. Frequently Asked Questions</h2>
<p style="margin-bottom: 2em; line-height: 1.9;"><strong>Q1. Why does the error point to line 1 even though my code looks fine?</strong><br />
A: n8n’s sandbox prepends a wrapper (<code>module.exports = async function(){ … }</code>). A missing closing brace in your code shifts the parser’s view, causing the wrapper’s first line to be flagged.</p>
<p style="margin-bottom: 2em; line-height: 1.9;"><strong>Q2. Can I use modern ES2022 features (e.g., optional chaining, nullish coalescing)?</strong><br />
A: Yes – n8n runs on Node 18, which fully supports these features. Ensure linting is set to <em>ECMAScript 2022</em>.</p>
<p style="margin-bottom: 2em; line-height: 1.9;"><strong>Q3. Is there a way to see the *exact* code that n8n sends to Node?</strong><br />
A: Open **Developer Tools → Sources → “Function node”** – you’ll see the generated wrapper with your code inserted.</p>
<div style="margin: 50px 0;">
<hr />
</div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">9. Next Steps</h2>
<ul style="margin-bottom: 2em; line-height: 1.9; list-style-type: disc; padding-left: 1.5em;">
<li>If the Function node still fails after syntax correction, investigate <strong>runtime errors</strong> (network timeouts, invalid JSON) in the sibling pages linked above.</li>
<li>Consider extracting complex logic into a <strong>custom n8n node</strong> or an <strong>external JavaScript file</strong> for easier testing and version control.</li>
</ul>
<div style="margin: 50px 0;">
<hr />
</div>
<h2 style="margin-bottom: 45px; line-height: 1.3;">Conclusion</h2>
<p style="margin-bottom: 2em; line-height: 1.9;">Syntax errors in n8n’s Function node are almost always a matter of missing punctuation, improper <code>await</code> usage, or scope confusion. By enabling line numbers, linting, and the “Execute Node” button, you can pinpoint the exact line, apply the targeted fix shown in the tables, and verify success instantly. Follow the production checklist to keep your workflows secure and maintainable, and you’ll see fewer interruptions and smoother automation in real‑world deployments.</p>

Step by Step Guide to Fix n8n Function Node Syntax Errors
Who this is for: Workflow developers who receive “Unexpected token” or “Missing ) after argument list” errors in n8n’s Function node and need a fast, reliable way to locate and fix them. We cover this in detail in the n8n Node Specific Errors Guide.
Quick Diagnosis
Problem: “Unexpected token” or “Missing ) after argument list” errors appear when a Function node runs.
Quick fix: Open the Function node → enable “Show line numbers” → locate the highlighted line → correct the JavaScript syntax (e.g., close brackets, add missing commas, use proper await/return).
One‑click test: Click “Execute Node” after fixing; the node should return a green checkmark and the expected output.
1. Why Function‑Node Syntax Errors Occur in n8n
If you encounter any n8n set node type mismatch resolve them before continuing with the setup.
| Root Cause |
Typical Error Message |
Example |
Missing/extra punctuation (; , ( ) { }) |
SyntaxError: Unexpected token ) |
return { foo: bar } (missing comma) |
Wrong use of await/async |
SyntaxError: Unexpected identifier |
await $http.get(...) inside a non‑async function |
Variable scope misuse ($json, $item, $node) |
ReferenceError: $json is not defined |
return $json.id in a node that only has $item |
Reserved word collision (e.g., class, function) |
SyntaxError: Unexpected token ‘class’ |
const class = "test" |
| Incorrect string interpolation |
SyntaxError: Unexpected token ` |
return `User ${user.id}` (missing back‑ticks) |
n8n’s Function node runs pure JavaScript (Node.js v18) in a sandbox. Any syntax that the Node runtime can’t parse aborts the node before the workflow continues.
2. Enable Precise Debugging Tools
If you encounter any n8n merge node type mismatch resolve them before continuing with the setup.
Turn on visual aids that point you directly to the offending line.
- Show line numbers – Click the gear icon ► Editor Settings ► toggle “Show line numbers”.
- Activate linting – In the same settings panel, enable “ESLint”. n8n underlines syntax problems in real time.
- Use the “Execute Node” button – Runs only the Function node, returning the exact error stack and the line number.
EEFA Note: In production workflows, never leave console.log statements that output sensitive data. Use $node["Debug"].json only in a dedicated debugging sub‑workflow.
3. Step‑by‑Step Workflow to Identify & Fix the Error
| Step |
Action |
Expected Result |
| 1 |
Open the failing Function node. |
Code editor appears. |
| 2 |
Click Execute Node (no input needed). |
Error panel shows line X and error message. |
| 3 |
Jump to the highlighted line (line numbers now visible). |
Cursor lands on the offending token. |
| 4 |
Apply the appropriate fix (see tables below). |
No red underline; linting passes. |
| 5 |
Re‑run Execute Node. |
Green checkmark + JSON output. |
| 6 |
Save the node and run the full workflow to confirm downstream nodes work. |
Workflow completes without errors. |
4. Common Syntax Mistakes & Exact Fixes
If you encounter any n8n function node reference error resolve them before continuing.
4.1 Missing Comma or Bracket
Problem: Objects need commas between properties and matching braces.
// ❌ Bad – missing comma and trailing brace
return {
id: item.id
name: item.name,
// ✅ Fixed – commas added, brace closed
return {
id: item.id,
name: item.name,
};
4.2 Improper await Usage
Problem: await can only be used inside an async function.
// ❌ Bad – node is not async
await $http.get('https://api.example.com');
// ✅ Fixed – wrap code in an async IIFE
return (async () => {
const response = await $http.get('https://api.example.com');
return response.json;
})();
4.3 Wrong Variable Scope
Problem: $json is unavailable in a “Function Item” node; use $item instead.
// ❌ Bad – $json undefined here
return $json.id;
// ✅ Fixed – reference the current item
return $item.json.id;
4.4 Reserved Word Collision
Problem: JavaScript reserves words like class.
// ❌ Bad – syntax error
const class = "premium";
// ✅ Fixed – rename variable
const userClass = "premium";
4.5 Bad Template Literals
Problem: Use back‑ticks for interpolation, not double quotes.
// ❌ Bad – no interpolation
return "User ID: ${item.id}";
// ✅ Fixed – back‑ticks enable ${}
return `User ID: ${item.id}`;
5. Advanced Debugging Techniques
*When simple fixes aren’t enough, these patterns help you capture runtime issues.*
| Technique |
How‑to |
When to Use |
| try / catch wrapper |
try { /* your logic */ } catch (e) { return { error: e.message }; }
|
To capture runtime errors that aren’t syntax‑related. |
| $node[“<NodeName>”].json inspection |
return $node["HTTP Request"].json;
|
When you need to verify the exact payload from a previous node. |
| console.error with process.env.NODE_ENV guard |
if (process.env.NODE_ENV !== 'production') console.error(e);
|
Prevents leaking errors in production logs. |
| Unit‑test snippet in the editor |
// Simulate input\nconst $item = { json: { id: 1 } };\n// Your code here
|
Quickly test logic without running the whole workflow. |
EEFA Warning: The sandbox strips require, process, and other Node core modules. Attempting to import them will throw a “Cannot find module” error, which appears as a syntax error but is actually a security restriction.
6. Production‑Ready Checklist for Function Nodes
- Linting enabled – no red squiggles before saving.
async only when needed – avoid unnecessary promises.
- No hard‑coded secrets – use n8n credentials or environment variables.
- Error handling – wrap external calls in
try / catch.
- Output validation – ensure the returned object matches downstream expectations (
return { json: {...} } vs. plain object).
- Remove debug
console.log – replace with $node["Debug"].json in a separate test workflow.
7. Frequently Asked Questions
Q1. Why does the error point to line 1 even though my code looks fine?
A: n8n’s sandbox prepends a wrapper (module.exports = async function(){ … }). A missing closing brace in your code shifts the parser’s view, causing the wrapper’s first line to be flagged.
Q2. Can I use modern ES2022 features (e.g., optional chaining, nullish coalescing)?
A: Yes – n8n runs on Node 18, which fully supports these features. Ensure linting is set to ECMAScript 2022.
Q3. Is there a way to see the *exact* code that n8n sends to Node?
A: Open **Developer Tools → Sources → “Function node”** – you’ll see the generated wrapper with your code inserted.
9. Next Steps
- If the Function node still fails after syntax correction, investigate runtime errors (network timeouts, invalid JSON) in the sibling pages linked above.
- Consider extracting complex logic into a custom n8n node or an external JavaScript file for easier testing and version control.
Conclusion
Syntax errors in n8n’s Function node are almost always a matter of missing punctuation, improper await usage, or scope confusion. By enabling line numbers, linting, and the “Execute Node” button, you can pinpoint the exact line, apply the targeted fix shown in the tables, and verify success instantly. Follow the production checklist to keep your workflows secure and maintainable, and you’ll see fewer interruptions and smoother automation in real‑world deployments.