5

I have setup my NodeJS session and performed the following test. I evaluate the following commands in ExternalLanguage cells.

test = 1+1

returns 2

test

returns 2

But when I try to get the value of the following builtin variable

global

Instead of returning its value, I get the following error

Failure["NodeJSError",<|
    "FailureCode" -> "Error",
    "MessageTemplate" -> "RangeError: Maximum call stack size exceeded",
    "Traceback" -> "..."
|>]

Please help me fix this. Could be because the output is too large. Btw it works fine on the nodejs console.

Note: I am using NodeJS version 10.16.0 LTS and Mathematica version 12.0.0.

Glorfindel
  • 547
  • 1
  • 8
  • 14
user13892
  • 9,375
  • 1
  • 13
  • 41

1 Answers1

4

It seems like global is already defined in the ExternalEvaluate environment. The ExternalEvaluate sets up a "context" to evaluate code within, and that context gets these variables defined within it:

ctx.require = require;
ctx.global = global;
ctx.process = process;
ctx.Buffer = Buffer;
ctx.console = console;

You can see how this is implemented in Applications/Wolfram Desktop.app/Contents/SystemFiles/Components/ExternalEvaluate_NodeJS/ Resources/eval.js.

I expect this is not strictly a bug but rather an implementation detail.

Unfortunately, it appears you're not able to use global as a user-defined name in ExternalEvaluate.

Carl Lange
  • 13,065
  • 1
  • 36
  • 70
  • I think you misunderstood my question. I know that global is a restricted variable in NodeJS and provides the same information as JavaScript running in browser does for variable window. The problem is I want to get the value of this variable not assign something to it. Its value is a huge JSON containing all the function and objects available in the current environment. But it is not coming out of ExternalEvaluate because of some call stack size issue. – user13892 Jun 17 '19 at 07:19
  • Aha, I did misunderstand your question. Unfortunately I won't be able to help for the next few weeks - I wish you good luck in finding your answer! – Carl Lange Jun 18 '19 at 09:17