{"record":{"id":"ba87f11a959c0fcb","repo":"n8n-io/n8n","slug":"unknown-identifier-name-is-not-defined","errorCode":null,"errorMessage":"Unknown identifier: '${name}' is not defined","messagePattern":"Unknown identifier: '(.+?)' is not defined","errorType":"exception","errorClass":"UnknownIdentifierError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/workflow-sdk/src/ast-interpreter/interpreter.ts","lineNumber":445,"sourceCode":"\t\t}\n\n\t\t// Check for dangerous globals (only when not shadowed by a local)\n\t\tvalidateIdentifier(name, this.getVariableNames(), node, this.sourceCode);\n\n\t\t// Check if it's an SDK function\n\t\tif (this.sdkFunctions.has(name)) {\n\t\t\treturn this.sdkFunctions.get(name);\n\t\t}\n\n\t\t// Allow certain safe built-ins\n\t\tif (name === 'undefined') return undefined;\n\t\tif (name === 'null') return null;\n\t\tif (name === 'true') return true;\n\t\tif (name === 'false') return false;\n\t\tif (name === 'NaN') return NaN;\n\t\tif (name === 'Infinity') return Infinity;\n\n\t\tthrow new UnknownIdentifierError(name, node.loc ?? undefined, this.sourceCode);\n\t}\n\n\t/**\n\t * Visit a template literal.\n\t * Handles n8n runtime variables by preserving them as escaped strings.\n\t */\n\tprivate visitTemplateLiteral(node: ESTree.TemplateLiteral): string {\n\t\tlet result = '';\n\n\t\tfor (let i = 0; i < node.quasis.length; i++) {\n\t\t\tconst quasi = node.quasis[i];\n\t\t\t// Use cooked value (with escape sequences processed), or raw if cooked is null\n\t\t\tresult += quasi.value.cooked ?? quasi.value.raw;\n\n\t\t\t// If there's an expression after this quasi\n\t\t\tif (i < node.expressions.length) {\n\t\t\t\tconst expr = node.expressions[i];\n\t\t\t\tconst value = this.evaluateTemplateExpression(expr);","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/workflow-sdk/src/ast-interpreter/interpreter.ts#L427-L463","documentation":"When resolving a bare identifier reference (not in a call), the interpreter at interpreter.ts:418-445 checks in order: locally declared variables (including auto-renamed ones), dangerous globals (rejected by `validateIdentifier`), SDK functions, and safe built-ins (`undefined`, `null`, `true`, `false`, `NaN`, `Infinity`). If the name matches none of these, it throws `UnknownIdentifierError`.","triggerScenarios":"Referencing an undeclared variable: `x` where `x` was never declared with `const`. Note that blocked globals like `console`, `Math`, `Date`, `process`, `fetch` are caught earlier by `validateIdentifier` (throwing `SecurityError`), so this throw is specifically for names that are simply unknown — not dangerous, just undefined.","commonSituations":"Typo in a variable name; referencing a variable from an outer scope that isn't in SDK scope; using an identifier that was declared in a different code path.","solutions":["Declare the variable with `const` before referencing it","Check spelling against declared variable names","For globals: use SDK alternatives (e.g., `$now`/`$today` for dates, n8n expressions for Math)"],"exampleFix":"// before\nconst result = myVarible; // typo\n\n// after\nconst result = myVariable;","handlingStrategy":"validation","validationCode":"import { ALLOWED_SDK_FUNCTIONS } from '@n8n/workflow-sdk/ast-interpreter/validators';\n\nconst SAFE_BUILTINS = new Set(['undefined', 'null', 'true', 'false', 'NaN', 'Infinity']);\n\nfunction findUndefinedReferences(code: string, declaredVars: Set<string>): string[] {\n  const ast = parse(code, { ecmaVersion: 'latest', sourceType: 'module' });\n  const undefined: string[] = [];\n  walk(ast, (node) => {\n    if (\n      node.type === 'Identifier' &&\n      !declaredVars.has(node.name) &&\n      !ALLOWED_SDK_FUNCTIONS.has(node.name) &&\n      !SAFE_BUILTINS.has(node.name)\n    ) {\n      // Exclude property names and callee names (they are contextual)\n      undefined.push(node.name);\n    }\n  });\n  return [...new Set(undefined)];\n}","typeGuard":null,"tryCatchPattern":"import { UnknownIdentifierError } from '@n8n/workflow-sdk/ast-interpreter/errors';\n\ntry {\n  interpretSDKCode(sdkCode, sdkFunctions);\n} catch (e) {\n  if (e instanceof UnknownIdentifierError) {\n    // show the identifier name and suggest declaring it or checking spelling\n  }\n  throw e;\n}","preventionTips":["Declare all variables with `const` before referencing them","Spell-check variable names consistently","Remember that globals like `console`, `Math`, `Date` are blocked — use SDK alternatives"],"tags":["sdk-interpreter","identifier","undefined-variable","typo"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}