3

I'm using org-mode in Spacemacs and have this code block:

#+BEGIN_SRC js :var payload=access-token-payload
let parsedPayload = JSON.parse(access-token-payload);
return parsedPayload.access_token;
#+END_SRC

Expected behavior: The code executes when I press C-c C-c

Actual behavior: I get an error saying No org-babel-execute function for js!. This should be supported since org-babel is present. I code a lot of Node and Javascript applications so Node is in my path.

1 Answer 1

3

You need to enable evaluation of js code. "Section 16.9" of org manual states:

By default, only 'emacs-lisp' is enabled for evaluation. To enable or disable other languages, customize the `org-babel-load-languages' variable either through the Emacs customization interface, or by adding code to the init file as shown next:

In this example, evaluation is disabled for 'emacs-lisp', and enabled for 'R'.

(org-babel-do-load-languages
  'org-babel-load-languages
  '((emacs-lisp . nil)
    (R . t)))

The provided example is not totally clear IMHO but that works. Another way to enable a language is to require the org babel module for the language, eg here:

M-: (require 'ob-js)
3
  • This is strange because I was using bash, python and org code blocks without any issue, out of the box. Thanks.
    – Mario Gil
    Dec 17, 2019 at 19:35
  • I cannot find ob-js in melpa or melpa-stable. Where is ob-js being maintained?
    – ksinkar
    Sep 12, 2021 at 7:56
  • It is included in org! org-9.4.6.tar contains -rw-r--r-- elpa/elpa 7397 org-9.4.6/ob-js.el
    – JeanPierre
    Sep 16, 2021 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.