Am about to give up on getting this package working have tried the following options:

  1. From the prettier docs, installed the package from melpa and added the following to init.el:

    (require 'prettier-js) (add-hook 'js2-mode-hook 'prettier-js-mode)

    Running M-x prettier-js results in the error: Searching for program: No such file or directory, prettier

  2. Tried the use-package configuration from the answer: activate prettier-js-mode after every save

    Running M-q results in the error: Autoloading failed to define function prettier and using M-x prettier-js again results in Searching for program: No such file or directory, prettier.

Really not sure what the problem is here, the package is downloaded and present in my elpa directory. Any help is greatly appreciated.

  • What OS are you using, how did you installed prettier and what is the path to it's executable (execute which prettier in your shell to get it)? – Oles Savluk Sep 29 '17 at 17:35

You need to have the program prettier installed on your system. See git repo here.

After you have done this, use following code in your init.el:

(require 'prettier-js)
(add-hook 'js2-mode-hook 'prettier-js-mode)
(add-hook 'web-mode-hook 'prettier-js-mode)

Only if that is working you can think about replacing the above lines with a use-package definition.

  • 1
    Doing that and trying to run M-x prettier-js from either web-mode or js2-mode results in the error Searching for program: No such file or directory, prettier – Bauhaus Jul 15 '17 at 4:42
  • 1
    of course the installed program prettier needs to be installed in system PATH. So it could be found and called by emacs. You do not write which operating system you use, so it is hard to tell what you should do about this. – jue Jul 17 '17 at 9:02

Using use-package you can ensure it'll be available to your emacs. Here is my snippet:

(use-package prettier-js
  :after js2-mode
  (add-hook 'js2-mode-hook 'prettier-js-mode)
  (add-hook 'web-mode-hook 'prettier-js-mode)
  (setq prettier-js-args '("--trailing-comma" "all"
                           "--bracket-spacing" "false"))

  (defun enable-minor-mode (my-pair)
    "Enable minor mode if filename match the regexp.  MY-PAIR is a cons cell (regexp . minor-mode)."
    (if (buffer-file-name)
        (if (string-match (car my-pair) buffer-file-name)
            (funcall (cdr my-pair)))))
  (add-hook 'web-mode-hook #'(lambda ()
                                '("\\.jsx?\\'" . prettier-js-mode)))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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