prettier / prettier-emacs

Minor mode to format JS code on file save
http://jlongster.com/A-Prettier-Formatter
375 stars 54 forks source link

Internal error when try prettier #20

Open ppasieka opened 6 years ago

ppasieka commented 6 years ago

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?

ryanolsonx commented 6 years ago

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

ryanolsonx commented 6 years ago

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)
ppasieka commented 6 years ago

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

rcoedo commented 6 years ago

@ppasieka I'm sorry but I don't have a windows machine to try this out. Could it be related to this issue? https://github.com/prettier/prettier-emacs/issues/25

ryanolsonx commented 6 years ago

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.

rcoedo commented 6 years ago

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

Thanks for pointing it out!

ryanolsonx commented 6 years ago

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

ryanolsonx commented 6 years ago

@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 😉 )

ppasieka commented 6 years ago

@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")
nickserv commented 6 years ago

Seems related to #25