When evaluating this code in an org-mode document:
const sq = x => x * x;
const cube = x => sq(sq(x));
return cube(4);
I was getting the error:
> require('sys').print(require('sys').inspect(function(){
> ^
> TypeError: require(...).print is not a function
I tracked it down to a js function wrapper in `ob-js.el.gz`:
(defvar org-babel-js-function-wrapper
"require('sys').print(require('sys').inspect(function(){\n%s\n}()));"
"Javascript code to print value of body.")
The `sys` module is long deprecated, and I can’t even see evidence that `print` was ever a valid function… but it used to work, so it must have been there at some point! Looking at the (I think current) source code for ob-js.el it’s still using “sys.print”.
Anyhoo, because it’s a `defvar` I don’t think it’s customizeable (right?), so I just had to re-eval the function with a different wrapper string:
(defvar org-babel-js-function-wrapper
"console.log(JSON.stringify(require('util').inspect(function(){\n%s\n}())));"
"Javascript code to print value of body.")
Not sure if that’s equivalent, but it seems ok so far (I had to add JSON.stringify… which seems like it shouldn’t do anything after util.inspect - but fixes a bunch of output formatting wierdness).
const sq = x => x * x;
const cube = x => sq(sq(x));
return cube(4);
Shows:
> RESULTS:
> : 256
@phuhl Thanks for the solution. It works now