3 added 273 characters in body; edited tags; edited title
source | link

Cannot jump to definition in js2-mode or Tern

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 get this workingcorrectly jump to a Javascript definition in emacs?

Here is a sample of code, where I am using the "jump-to-definition" function works in other environments like WebStorm:

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 correctincorrect, but my Nodejs environment is not set up. What is wrong with my node environment, and how can I fixdon't know what it? is. Any suggestions would be appreciated.

;; 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)))

Cannot jump to definition in js2-mode

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. How can I get this working?

Here is a sample of code, where the "jump-to-definition" function works in other environments like WebStorm:

But it does not work when I put the point over someFunction() above and run M-x ac-js2-jump-to-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 correct, but my Nodejs environment is not set up. What is wrong with my node environment, and how can I fix it?

;; 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")

Cannot jump to definition in js2-mode or Tern

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":

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.

;; 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)))
2 edited tags; edited title
| link

ac-js2-jump-to-definition not working Cannot jump to definition in Nodejsjs2-mode

1
source | link

ac-js2-jump-to-definition not working in Nodejs

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. How can I get this working?

Here is a sample of code, where the "jump-to-definition" function works in other environments like WebStorm:

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. 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 correct, but my Nodejs environment is not set up. What is wrong with my node environment, and how can I fix it?

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")