Javascript in node function ERROR: Cannot read properties of undefined (reading 'every') [Line 852]

Hi,
i’m tring to insert some line of javascript in node function to work on Amazon Signing V4.
So, when i try to insert some line of javascript after the execution appear “ERROR: Cannot read properties of undefined (reading ‘every’) [Line 852]” And the details are:

TypeError: Cannot read properties of undefined (reading 'every')
    at Object.normalizeItems (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/NodeExecuteFunctions.js:852:23)
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function/Function.node.js:97:34)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/src/Workflow.js:598:28)
    at async /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:557:53

So i don’t understand if is a core error/bug or my fault…The Javascript code is simple as this:

var crypto = require("crypto-js");

function getSignatureKey(key, dateStamp, regionName, serviceName) {
    var kDate = crypto.HmacSHA256(dateStamp, "AWS4" + key);
    var kRegion = crypto.HmacSHA256(regionName, kDate);
    var kService = crypto.HmacSHA256(serviceName, kRegion);
    var kSigning = crypto.HmacSHA256("aws4_request", kService);
    return kSigning;
}

(I have imported with NPM “crypto-js” and also “exported” the module for n8n)
Thank you.

Hey @Giorgio,

Is that all you have in your function node? It looks like you are using some variables which have no value set which could explain the undefined error.

1 Like

Thank you for the reply.
Yes it’s the only Code in my function node, and all the variable in the code are declared.
So i do not understand the kind of error.

Hello @Giorgio,

I’ve had this error so many times too - because it just doesn’t mean anything.
The function node has no “return data” - it’s just a “void function” … terminated with this weird error message.

Write “return items” (or your real data) and the error disappears :wink:

3 Likes

Hey @Giorgio,

I suspect then if that us all your function node contains there is a lot more that needs to be added like the return mentioned above and I can’t see where the items you are passing in are defined.

1 Like

Yes, thank you very much!
I have tried this solution and thene the error disappear :smile:
So i have understand what kind of error was, there must be an “output”.

3 Likes