prettier / prettier-emacs

Minor mode to format JS code on file save

Home Page:http://jlongster.com/A-Prettier-Formatter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Internal error when try prettier

ppasieka opened this issue · comments

My env:
Windows 10
Spacemacs 0.200.10 with emacs 25.3.1
prettier 1.7.4

When I save js file prettier try to run but ends up with error

Wrote c:/Users/Piotr/AppData/Local/Temp/prettier18116vTA.js
helm-M-x: Invalid rcs patch or internal error in prettier-js--apply-rcs-patch

What can be a problem?

I'm having this issue as well. Does anybody know a work around?

I'd love to see this addressed.

Until it is, here's a quick workaround that you can add to your init.el file. You must have prettier installed globally for it to work (npm i -g prettier).

(defun prettier-format ()
  (call-process "prettier" nil "*prettier-output*" nil "--write" (buffer-file-name))
  (revert-buffer nil 'no-confirm t))

(defun run-prettier-on-save ()
  "Format current file if it's running tide mode"
  (interactive)
  (when (bound-and-true-p tide-mode)
    (prettier-format)))

(add-hook 'after-save-hook 'run-prettier-on-save)

@ryanolsonx unfortunately your solution doesn't work for me :( . Guess I still have to run prettier from shell.

@ppasieka I'm sorry but I don't have a windows machine to try this out. Could it be related to this issue? #25

Can we re-open this? It's still an issue, even if you don't have a Windows machine. I might have some time to try and dig into fixing this one.

@ryanolsonx Sorry, I hit the wrong button! I didn't want to close this.

Thanks for pointing it out!

Thanks @rcoedo.

I just got the latest package from Melpa and I still see the error whenever I save a typescript file.
Error: (error "Invalid rcs patch or internal error in prettier-js--apply-rcs-patch")

@rcoedo I noticed that the issue I've been having is related to diff.

I realized that my diff command was pointing to neovim/bin/diff.exe (which isn't the same as linux/mac diff). Once I removed that from my path, it fell back to a linux diff port that I have on my machine and my issues have been resolved. I think the diff that is working for me is one from Cygwin.

So - I do think this issue is strongly related to the diff issue.

(side note: neovim was a mistake 😉 )

@rcoedo I also noticed that the issue I've been having is related to diff executable.

When I reordered my PATH settings that cygwin/diff takes precedence before system/diff then prettier starts to work correctly.

I guess that we should add this special requirement for windows users to Readme.

"Be sure to use gnu diff.exe (e.g. from cygwin) instead of windows diff.exe"

in emacs you can check which version is used by evaluating:

(executable-find "diff")

Seems related to #25