Attempting to set global variable 'key' error

#1

With the same function, that is requesting using API fetch, get, and evalMetrics with some manipulation on data returned, I can run it on client side normally.
I can conclude that the error is compiler error, ie: JavaScript engine related (although not sure) but not in the logic for sure. I couldn’t spot the error after many tries.
Hints:
no arrow function (=>).
no spread notation (…).

In my last post, @Scott Kurinskas said C3 is running Rhino v1.7.7. and that It supports some EcmaScript (ES) 6 features but is not fully ES 6 compliant.
What could be the error otherwise, it’s a hell of a problem to debug in local but can’t in server :open_mouth:
the error is: C3.client.ActionError {name: "ActionError", message: "Attempting to set global variable 'key' (within BillingAccount.getAllDataDailyV3)."

0 Likes

#2

did you put a var in front of your variable key ? C3 doesn’t allow global variables…

1 Like

#3

I still can’t figure out, I was provisioning each time with minor changes and spotting bad line using return and logger like the early programming days :open_mouth::open_mouth: .
I’m using Jasmine tester now to ease the process, not provisioning.

I wonder also how to debug in Server, if any technique is present, I would be thankful.

Thanks

0 Likes

#4

As @lpoirier mentioned, that specific error message occurs whenever your code attempts to set a global variable, which is not allowed in application code in the server runtime.

So somewhere your code is doing:

key = "value";

when you should instead be doing:

var key = "value";

You will not get that error when running the same code through the Jasmine tester, it is specific to the server runtime.

You could try using a tool like ESLint to validate your JavaScript code. The specific ESLint rule for this case is no-global-assign.

0 Likes