pnpm: Prettier plugin doesn't load automatically after `pnpm` `7.0.0` hoisting
pnpm version: 7.0.1
Code to reproduce the issue:
Installing prettier
and prettier-plugin-tailwindcss
pnpm add --save-dev prettier prettier-plugin-tailwindcss
Expected behavior
prettier-plugin-tailwindcss
loads automatically as it’s now hoisted since pnpm
7.0.0
Running prettier file.tsx
should print the file content formatted correctly with tailwindcss
classes sorted.
Actual behavior
prettier-plugin-tailwindcss
doesn’t load automatically, and requires specifying the plugins
option at prettier
config.
Running prettier file.tsx
prints the file content formatted correctly but doesn’t load/use prettier-plugin-tailwind
.
Debugging
- Installing the
prettier
andprettier-plugin-tailwindcss
withnpm
8.6.0
works as expected. - Replacing the symlinked
node_modules/prettier
installed withpnpm
with thenpm
version made it work as expected.
Making plugins load manually
For prettier
to load plugins as expected from my testing with pnpm
version 7.0.0
to 7.20.0
, its required to specify the plugins
option in the prettier
config:
// .prettierrc.js
module.exports = {
arrowParens: 'always',
printWidth: 120,
semi: false,
singleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
useTabs: false,
plugins: [require('prettier-plugin-tailwindcss')],
}
I also moved prettier
config from JSON to JavaScript, to use plugins: [require('prettier-plugin-tailwindcss')]
instead of "plugins": ["prettier-plugin-tailwindcss"]
for text editors to resolve the plugins correctly as well.
Additional information
node -v
prints: v18.0.0- Windows, macOS, or Linux?: Linux
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 19
- Comments: 26 (2 by maintainers)
Commits related to this issue
- fix: symlinked hoisting should not override files in the root of node_modules (#5663) — committed to pnpm/pnpm by zkochan 2 years ago
Is this fixed? I really want to use pnpm as my main package manager and this is what’s stopping me
Would love to see some kind of follow up to this, if at all possible. I’m sure the number of people using both prettier and pnpm has to be large and growing by the day.
I came across this thread when I was facing a similar issue. As the plugin page prettier-plugin-tailwindcss#installation suggests, adding the following in my
.prettierrc.js
solved the issue.I can confirm I have also come across this issue today as a pnpm user.
Even happens when adding:
[require('prettier-plugin-tailwindcss')]
to.prettierrc.js
or"plugins": ["prettier-plugin-tailwindcss"]
to.prettierrc
I encountered #6793 earlier today and wanted to see if prettier-plugin-jsdoc would resolve my issue. Unfortunately, it doesn’t seem like I can use any plugins with pnpm…
Manually using “Format document with” gives this popup:
Just saving with “format on save” gives no errors in the extension logs but does nothing to the saved file (ie: semicolons or the trailing new line at the end of files not being added). I was also kind of expecting to see
["INFO" - <time>] Formatting completed in x ms.
but I don’t see that either, so I assume something silently failed along the way.For additional context:
.prettierrc
@eldair here’s a workaround here I came across at https://github.com/prettier/prettier/issues/13276 - it’s specific to
@prettier/plugin-php
and it coversvscode
as well. Hope that helps.Thanks everyone for the update! I’ll close this issue as it was specific to automatically loading
prettier
plugins withpnpm
and it’s no longer relevant to have it opened as this feature is being removed.I’ve been loading
prettier
plugins withpnpm
manually for a while now and it works fine. For anyone still facing issues loadingprettier
plugins manually, please feel free to open an issue onprettier
repo if there’s no issue opened already.Here’s the config I’m using currently:
Yeah, if I’m understanding https://github.com/prettier/prettier/pull/14759 correctly, the next major version of Prettier (3.0.0) will have the plugin autoload / automatic search feature removed.
@oedotme thanks a lot!! I managed to make it work 😃
Hey everyone, I wanted to highlight that
pnpm
already works withprettier
andprettier-plugin-tailwindcss
with a manual configuration step forprettier
.For that, I’ve updated the issue description to include Making plugins load manually section as a solution for this issue in the meanwhile.
Not really, it’s still behaving the same before and after
pnpm
hoisting.The thing is I was expecting after hoisting,
prettier
would load plugins automatically but it didn’t. That’s why I opened this issue.What I understand so far that
prettier
by default tries to find plugins only in the parent directory whereprettier
binary is executed and that works withnpm
. It’s supposed to work withpnpm
too after hoisting but it doesn’t for some reason. I don’t know if it’s related to symlinking or because even after hoistingprettier
still executes fromnode_modules/.pnpm
.When I just replaced the
node_modules/prettier
installed withpnpm
with another installed withnpm
it worked as expected.