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
prettierandprettier-plugin-tailwindcsswithnpm8.6.0works as expected. - Replacing the symlinked
node_modules/prettierinstalled withpnpmwith thenpmversion 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 -vprints: 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.jssolved 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.jsor"plugins": ["prettier-plugin-tailwindcss"]to.prettierrcI 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-phpand it coversvscodeas well. Hope that helps.Thanks everyone for the update! I’ll close this issue as it was specific to automatically loading
prettierplugins withpnpmand it’s no longer relevant to have it opened as this feature is being removed.I’ve been loading
prettierplugins withpnpmmanually for a while now and it works fine. For anyone still facing issues loadingprettierplugins manually, please feel free to open an issue onprettierrepo 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
pnpmalready works withprettierandprettier-plugin-tailwindcsswith 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
pnpmhoisting.The thing is I was expecting after hoisting,
prettierwould load plugins automatically but it didn’t. That’s why I opened this issue.What I understand so far that
prettierby default tries to find plugins only in the parent directory whereprettierbinary is executed and that works withnpm. It’s supposed to work withpnpmtoo after hoisting but it doesn’t for some reason. I don’t know if it’s related to symlinking or because even after hoistingprettierstill executes fromnode_modules/.pnpm.When I just replaced the
node_modules/prettierinstalled withpnpmwith another installed withnpmit worked as expected.