jscheid / prettier.el

Prettier code formatting for Emacs.
GNU General Public License v3.0
163 stars 11 forks source link

Prettier fails to find config and times out after upgrade to latest version #132

Closed cmatzenbach closed 4 months ago

cmatzenbach commented 4 months ago

Describe the bug First off, wanted to say thank you so much for this package, it is the lifeblood of my workflow. However, today I updated all my emacs packages (including the lsp language servers, not sure if that matters or not), and after restarting, the package no longer works and I keep getting the error Could not sync Prettier config, consider setting ‘prettier-mode-sync-config-flag’ to nil: (error "Prettier timed out after 20 seconds"). For a bit of background - the repo I work in daily uses nvm, which is locked in to node 12.16.1. The repo also has prettier installed as a dependency in node_modules and has a .prettierrc.json in the project root (all the contributors use prettier). I have put the link to my prettier-info gist below.

I read through the readme several times, and saw that this extension is looking for node in the exec-path, which after analyzing I realized it was not present (I am not sure if it was present before and was removed after the upgrade; I never had explicitly set the exec-path to my project's node version in my init.el, so I am not sure how it found it before). Regardless I manually set it after troubleshooting (as you will see in the gist), but that did not solve the problem either. For reference:

matzy at omnisci in ~/Projects/immerse (master●) 
$ node --version
v12.16.1

matzy at omnisci in ~/Projects/immerse (master●) 
$ which node
/home/matzy/.nvm/versions/node/v12.16.1/bin/node

matzy at omnisci in ~/Projects/immerse (master●) 
$ npm list prettier
immerse@7.2.0-dev /home/matzy/Projects/immerse
└── prettier@2.0.5 

Relevant entry in init.el:

(setq exec-path (append exec-path '("/home/matzy/.nvm/versions/node/v12.16.1/bin/node")))

In case it helps, the projects .prettierrc.json file:

{
  "arrowParens": "always",
  "endOfLine": "lf",
  "jsxSingleQuote": false,
  "semi": false,
  "singleQuote": false,
  "trailingComma": "none",
  "overrides": [
    {
      "files": "*.json",
      "options": {
        "parser": "json"
      }
    }
  ]
}

Link to M-x prettier-info output Gist

To Reproduce Open a typescript/javascript/etc file in my project, enable prettier-mode.

Expected behavior prettier-mode should startup without errors and format my buffer on save as usual.

Additional context I was wondering, does this have any relation to lsp/the lsp language servers being used for a given project? I was trying to figure out if updating lsp and the servers could somehow have been involved, and tried to play around with disabling lsp and such, but never had any success. I would assume there isn't any interaction though, as lsp isn't a dep for this package.

I read through both the elisp and js code, but I don't know how to debug elisp and wasn't sure when the js code is triggered and how to capture console logs from it to try and determine the issue. This package is a lifesaver for me, so I am more than willing to help with any debugging to help fix the issue if you can instruct me how to do so. To be honest, if my elisp ever gets better, I would even love to help maintain/contribute to it, that's how much of a lifesaver this package has been for me :)

Thank you!

jscheid commented 4 months ago

Could you check if there's anything interesting in the *prettier (local)* buffer? It should be empty if all is working, otherwise please share it here.

jscheid commented 4 months ago

Also thanks for the kind words, I'm glad it's useful to you!

cmatzenbach commented 4 months ago

Could you check if there's anything interesting in the *prettier (local)* buffer? It should be empty if all is working, otherwise please share it here.

@jscheid So this is interesting...when I first open a .ts file, the *prettier (local)* is indeed there and is blank. However, once I save a file, the buffer disappears. When I do prettier-restart it comes back, and when I save again it disappears. I've attached a screencast, with the Messages buffer open in a separate window:

https://github.com/jscheid/prettier.el/assets/15268289/437a6bb7-9629-474a-b6fc-978917b34d73

jscheid commented 4 months ago

Hmm, interesting. It might be the node process crashing. Please set prettier-keep-server-buffer-flag to a truthy value and try again?

cmatzenbach commented 4 months ago

Ok that does prevent that buffer from crashing, but it still is blank, even after saving.

jscheid commented 4 months ago

From memory we're never killing the process except on user request (i.e. prettier-restart.) So this would mean something else is killing the process, either inside Emacs (a package that's a bit trigger happy with kill-process perhaps) or outside (the OOM killer maybe) -- or it crashes. If it's not kill-process I'd expect this to get triggered, is it?

It would be good to rule out interference from another package, could you try loading just this package alone in an otherwise vanilla Emacs and see if it still breaks?

cmatzenbach commented 4 months ago

Hmmm interesting, no, I'm never seeing that message come through in the *Messages* buffer...interestingly enough though, when trying through a vanilla emacs setup, it does indeed work as normal. I'll try disabling various minor modes enabled to see if I can isolate which package is causing the interference.

cmatzenbach commented 4 months ago

Hey what do you know! I updated all my packages just now, and it works again! No idea what happened, but all good now.

Vielen dank fuer ihre hilfe, gruesse aus der Staaten! 😄

jscheid commented 4 months ago

Ha, ok then 🤷 all the better, glad it works now. Gruß zurück!