prettier-java
prettier-java copied to clipboard
How do specify plugins without requiring a fully qualified path?
I have installed prettier
and prettier-plugin-java
globally:
$ npm -g list
/home/larsks/lib/npm-packages/lib
├── [email protected]
└── [email protected]
Attempting to format some Java code like this failed:
$ prettier Example.java
[error] Cannot find package 'prettier-plugin-java' imported from /home/larsks/tmp/java/noop.js
That's unpleasant but perhaps expected based on #508. But this also fails:
$ prettier --plugin prettier-plugin-java Tile.java
[error] Cannot find package 'prettier-plugin-java' imported from /home/larsks/tmp/java/noop.js
The only thing that worked was this:
$ prettier --plugin ~/lib/npm-packages/lib/node_modules/prettier-plugin-java/dist/index.js Tile.java
[error] Cannot find package 'prettier-plugin-java' imported from /home/larsks/tmp/java/noop.js
And...that's a lot of typing. I would put that into .prettierrc.yaml
, but neither ~
nor $HOME
work in that file to refer to my home directory, which means that I can't suggest this to colleagues as a generic solution, and if I happen to have different home directories in different environments (which I do) I can't use the same configuration file (and I can't make .prettierrc
part of a project repository, because it would need to be modified by everybody in their own working directory).
Is there any way to make this work in a more graceful fashion?
This appears to be identical to #630. See my response there for a temporary workaround.
Closing as duplicate of #630.