Your browser does not support JavaScript!
Upvotes Anonymous 1 User 0

How to resolve "Undeclared variable or function 'module'" error thrown by js2-mode in Spacemacs

If you've setup Tern for Spacemacs, and you're seeing the following error:
Undeclared variable or function 'module'
add the following line to the user-init section of your .spacemacs file:
(setq js2-include-node-externs t)
For example, here's what my user-init section looks like:
What does this line do?
In your js2-mode.el file (see .emacs.d/elpa/js2-mode/), there's a section that looks like this:
(defvar js2-node-externs
  (mapcar 'symbol-name
          '(__dirname __filename Buffer clearInterval clearTimeout require
            console exports global module process setInterval setTimeout
            querystring setImmediate clearImmediate))
  "Node.js externs.
Set `js2-include-node-externs' to t to include them.")
Setting this variable helps define module for js2-mode

Thanks to this answer on Stack Exchange for helping me figure this out.
Was this helpful?

Tags

Comments

Leave a Comment

I agree to the Terms of Service
Design © 2015, Downranked, LLC.,
Original user code contributions under MIT License