{"record":{"id":"03e724afdfd8ec3b","repo":"n8n-io/n8n","slug":"imports-are-not-supported","errorCode":null,"errorMessage":"Imports are not supported","messagePattern":"Imports are not supported","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/tournament/src/VariablePolyfill.ts","lineNumber":128,"sourceCode":"\t},\n\tArrowFunctionExpression(path, parent: namedTypes.ArrowFunctionExpression, dataNode) {\n\t\t// A concise arrow body that is a bare identifier (`() => process`) must be\n\t\t// routed through the data context like any other free read. Params are not\n\t\t// the body, and body identifiers that reference a param are left alone by\n\t\t// polyfillVar's in-scope check.\n\t\tif (parent.body === path.node) {\n\t\t\tpolyfillVar(path, dataNode);\n\t\t}\n\t},\n};\n\nexport const jsVariablePolyfill = (\n\tast: types.namedTypes.File,\n\tdataNode: DataNode,\n): StatementKind[] | undefined => {\n\tvisit(ast, {\n\t\tvisitImportExpression(_path) {\n\t\t\tthrow new Error('Imports are not supported');\n\t\t},\n\t\tvisitIdentifier(path) {\n\t\t\tthis.traverse(path);\n\t\t\tconst parent: ParentKind = path.parent.node;\n\n\t\t\t// This is for tmpl compat\n\t\t\tif (EXEMPT_IDENTIFIER_LIST.includes(path.node.name)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tswitch (parent.type) {\n\t\t\t\tcase 'AssignmentPattern':\n\t\t\t\tcase 'Property':\n\t\t\t\tcase 'MemberExpression':\n\t\t\t\tcase 'OptionalMemberExpression':\n\t\t\t\tcase 'VariableDeclarator':\n\t\t\t\tcase 'ArrowFunctionExpression':\n\t\t\t\t\tif (!customPatches[parent.type]) {","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/tournament/src/VariablePolyfill.ts#L110-L146","documentation":"Error('Imports are not supported') is thrown by jsVariablePolyfill's visitor when it encounters a visitImportExpression, i.e. a dynamic import() call inside an n8n expression. Static import statements would have already failed parsing for an expression context, so this guard specifically catches the dynamic form.","triggerScenarios":"An n8n expression chunk contains a dynamic import, e.g. '{{ import(\"lodash\") }}' or '{{ await import(\"./helper\") }}'.","commonSituations":"A user expects to load a library on the fly from an expression; a pasted code snippet uses dynamic import for code splitting; a user attempts to reach Node built-ins via import.","solutions":["Use a Code node (JavaScript) which supports require() for permitted modules, instead of an inline expression.","If a helper value is needed in the expression, compute it upstream in a Set/Code node and reference the field via $json / $node[...].","Remove any import() call from inside {{ }}."],"exampleFix":"// before\n{{ (await import('lodash')).get($json, 'a.b') }}\n// after\n# In a Code node upstream:\n#   const _ = require('lodash');\n#   return [{ json: { val: _.get($input.all()[0].json, 'a.b') } }];\n# Then in the expression: {{ $json.val }}\n","handlingStrategy":"validation","validationCode":"// Reject dynamic import() in expressions at authoring time.\nif (/\\\\bimport\\\\s*\\\\(/.test(codeChunk)) {\n  throw new Error('dynamic import() is not supported in n8n expressions');\n}\n","typeGuard":"import { namedTypes } from 'ast-types';\nfunction isImportExpression(node: unknown): node is namedTypes.ImportExpression {\n  return !!node && (node as any).type === 'ImportExpression';\n}\n","tryCatchPattern":"try {\n  const compiled = buildExpression(chunks, hooks);\n} catch (e) {\n  if (e instanceof Error && /Imports are not supported/.test(e.message)) {\n    throw new UserError('import() is blocked in expressions; use a Code node with require().');\n  }\n  throw e;\n}\n","preventionTips":["Lint for 'import(' in user expressions before save.","Use a Code node for any module loading.","Surface a helpful message pointing to the Code node alternative.","Educate users that expressions are pure, module-less evaluators."],"tags":["n8n","expression","typescript","ast","imports","security"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}