I am performing Nodejs development in emacs, but my environment seems incorrect. For example, when I run ac-js2-jump-to-definition
, I get "no jump location found" in the minibuffer. Also when I run 'tern-find-definition`, I get "No definition found.".
How can I correctly jump to a Javascript definition in emacs?
Here is a sample of code, where I am using the "jump-to-definition":
In auth.js, I have this:
module.exports = function (options) {
options = options || {}
auth = {}
auth.someFunction = function () {
return "someFunction has been called"
}
return auth
}
Then I call auth
from here:
var auth = require('auth')()
auth.someFunction()
But it does not work when I put the point over someFunction()
above and run M-x ac-js2-jump-to-definition
or tern-find-definition
. Also, when I run js2-next-error
, the require
function in require('auth')()
above is selected and gives the message "Undeclared variable or function 'require'".
I suspect that my Javascript environment is incorrect, but I don't know what it is. Any suggestions would be appreciated.
Here is my relevant configuration from my init script:
;; JAVASCRIPT-MODE
;; js2-mode provides 4 level of syntax highlighting. They are * 0 or a negative value means none. * 1 adds basic syntax highlighting. * 2 adds highlighting of some Ecma built-in properties. * 3 adds highlighting of many Ecma built-in functions.
(setq js2-highlight-level 3)
(add-hook 'js2-mode-hook
(lambda ()
;; allow window resizing via M-l and M-h
(local-unset-key (kbd "M-l"))
(local-unset-key (kbd "M-h"))
(local-unset-key (kbd "M-j"))
(local-set-key (kbd "C-j") 'ac-js2-jump-to-definition)
(local-set-key (kbd "C-c C-n") 'js2-next-error)
(define-key js2-mode-map (kbd "C-j") 'ac-js2-jump-to-definition)
(linum-mode)
(js2-reparse t)
(ac-js2-mode)))
(add-to-list 'interpreter-mode-alist '("node" . js2-mode))
(add-to-list 'auto-mode-alist
'("\\.js$" . js2-mode))
(require 'js2-refactor)
(js2r-add-keybindings-with-prefix "C-c C-m")
(add-hook 'js2-mode-hook #'js2-refactor-mode)
(add-to-list 'load-path "~/.emacs.d/tern/emacs/")
(autoload 'tern-mode "tern.el" nil t)
(add-hook 'js-mode-hook (lambda () (tern-mode t)))