prettierd icon indicating copy to clipboard operation
prettierd copied to clipboard

Errors with `Error: Cannot find module 'prettier'` after `prettierd`'s update

Open gegoune opened this issue 1 year ago • 5 comments

HI there,

I have noticed an issue running prettierd recently, seems like installed paths are not quite matching package version:

❯ brew install fsouza/prettierd/prettierd
==> Fetching fsouza/prettierd/prettierd
==> Downloading https://registry.npmjs.org/@fsouza/prettierd/-/prettierd-0.25.4.tgz
[...]
❯ cat foo.js | prettierd foo.js
Error: Cannot find module 'prettier'
Require stack:
- /opt/homebrew/Cellar/prettierd/0.25.3/libexec/lib/node_modules/@fsouza/prettierd/dist/service.js
- /opt/homebrew/Cellar/prettierd/0.25.3/libexec/lib/node_modules/@fsouza/prettierd/node_modules/core_d/lib/server.js
- /opt/homebrew/Cellar/prettierd/0.25.3/libexec/lib/node_modules/@fsouza/prettierd/node_modules/core_d/lib/daemon.js
❯ ls -d /opt/homebrew/Cellar/prettierd/0.25.*
/opt/homebrew/Cellar/prettierd/0.25.4

Please note that no directory for version 0.25.4 is present when installed with Homebrew.


Thanks for prettierd, it's amazing!

gegoune avatar Nov 18 '24 21:11 gegoune

I have the same issue with macOS with Homebrew.

cc @fsouza

timharek avatar Dec 04 '24 18:12 timharek

hmm it looks like something broke with the upgrade? What are the contents of the prettierd prefix? Something like:

$ ls -l $(brew --prefix prettierd)

fsouza avatar Jan 04 '25 00:01 fsouza

That's pretty interesting now. I am no longer convinced is an issue with prettierd itself, but perhaps with homebrew instead.

I was just about to reply to your message, and have tested it just like in original post, and it worked just fine so I decided to upgrade to 0.26.0, which broke it once again, in the same fashion:

❯ cat test.js | prettierd test.js
Error: Cannot find module 'prettier'
Require stack:
- /opt/homebrew/Cellar/prettierd/0.25.4/libexec/lib/node_modules/@fsouza/prettierd/dist/service.js
- /opt/homebrew/Cellar/prettierd/0.25.4/libexec/lib/node_modules/@fsouza/prettierd/node_modules/core_d/lib/server.js
- /opt/homebrew/Cellar/prettierd/0.25.4/libexec/lib/node_modules/@fsouza/prettierd/node_modules/core_d/lib/daemon.js

❯ which prettierd
/opt/homebrew/bin/prettierd

❯ ls -l /opt/homebrew/bin/prettierd
lrwxr-xr-x 1 gegoune admin 40 Jan  4 11:38 /opt/homebrew/bin/prettierd -> ../Cellar/prettierd/0.26.0/bin/prettierd

❯ prettierd --version
prettierd 0.26.0

❯ ls -l $(brew --prefix prettierd)
lrwxr-xr-x 1 gegoune admin 26 Jan  4 11:33 /opt/homebrew/opt/prettierd -> ../Cellar/prettierd/0.26.0

gegoune avatar Jan 04 '25 10:01 gegoune

Can you try running prettierd stop or just pkill prettierd? If that fixes it, it's possible it's an issue with the caching, maybe we should detect that the cached prettier is gone and handle it.

fsouza avatar Jan 05 '25 00:01 fsouza

Oh, that fixed that indeed! Thank you! I will make mental note to run it after next update, but would be nice to handle it internally like you said. Let me update this issue's subject to better describe the issue.

gegoune avatar Jan 05 '25 02:01 gegoune