Errors with `Error: Cannot find module 'prettier'` after `prettierd`'s update
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!
I have the same issue with macOS with Homebrew.
cc @fsouza
hmm it looks like something broke with the upgrade? What are the contents of the prettierd prefix? Something like:
$ ls -l $(brew --prefix prettierd)
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
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.
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.