prettier-emacs icon indicating copy to clipboard operation
prettier-emacs copied to clipboard

Internal error when try prettier

Open ppasieka opened this issue 7 years ago • 10 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?

ppasieka avatar Nov 03 '17 06:11 ppasieka

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

ryanolsonx avatar Nov 22 '17 15:11 ryanolsonx

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 avatar Nov 22 '17 18:11 ryanolsonx

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

ppasieka avatar Nov 25 '17 08:11 ppasieka

@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

rcoedo avatar Jan 09 '18 07:01 rcoedo

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 avatar Jan 09 '18 15:01 ryanolsonx

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

Thanks for pointing it out!

rcoedo avatar Jan 09 '18 15:01 rcoedo

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 avatar Jan 09 '18 15:01 ryanolsonx

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

ryanolsonx avatar Jan 09 '18 16:01 ryanolsonx

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

ppasieka avatar Jan 12 '18 10:01 ppasieka

Seems related to #25

nickserv avatar Feb 28 '18 17:02 nickserv