fsouza/prettierd

Prettierd cannot find prettier plugins

datwaft opened this issue · 3 comments

Hello!

I am currently trying to use the plugin @trivago/prettier-plugin-sort-imports. As you can see in this test repository I created, both prettier and the prettier plugin are installed:

{
  "name": "prettierd_plugin_issue",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@trivago/prettier-plugin-sort-imports": "^3.2.0",
    "@types/chai": "^4.3.0",
    "@types/mocha": "^9.1.0",
    "chai": "^4.3.6",
    "mocha": "^9.2.2",
    "prettier": "^2.6.0",
    "typescript": "^4.6.2"
  }
}

When I try to format the package using prettier it works properly, using the plugin:

foo@bar:~$ npx prettier . --write
.prettierrc.json 40ms
package-lock.json 117ms
package.json 12ms
src/module.ts 206ms
test/module.spec.ts 23ms
tsconfig.json 5ms

image

But when I try to format the file test/module.spec.ts using prettierd the normal formatting for ; happens, but the imports are not ordered.

foo@bar:~$ cat test/module.spec.ts | prettierd test/module.spec.ts
import hello_world from "@src/module";
import { expect } from "chai";

describe("the module module", function () {
  it("should not return anything", function () {
    const returnValue = hello_world();
    expect(returnValue).to.be.undefined;
  });
});

image

If I try to manually specify the plugin in the .prettierrc.json file, this happens:

foo@bar:~$ cat test/module.spec.ts | prettierd test/module.spec.ts
Error: Cannot find module '@trivago/prettier-plugin-sort-imports'
Require stack:
- /home/datwaft/Issues/prettierd_plugin_issue/node_modules/prettier/index.js
- /home/datwaft/.nvm/versions/node/v17.1.0/lib/node_modules/@fsouza/prettierd/dist/service.js
- /home/datwaft/.nvm/versions/node/v17.1.0/lib/node_modules/@fsouza/prettierd/node_modules/core_d/lib/server.js
- /home/datwaft/.nvm/versions/node/v17.1.0/lib/node_modules/@fsouza/prettierd/node_modules/core_d/lib/daemon.js

image

The test repository can be found here: https://github.com/datwaft/prettierd_plugin_issue

I just executed prettierd restart and it works now, weird.

image

I think the issue can be closed now. I will do some more testing.

I just restarted the computer and it still works properly, so the issue can be closed.

Something weird is that I even reinstalled node trying to fix the issue, and the repository is a new one.

Sounds like this could be an issue with not restarting the server after updating prettierd. I'm going to try to think of a way to either do it automatically or suggest that users do it whenever upgrading prettierd. Ideally doing it automatically would be gold.