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 and prettier-plugin-tailwindcss with npm 8.6.0 works as expected.
  • Replacing the symlinked node_modules/prettier installed with pnpm with the npm 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

Most upvoted comments

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.

# .prettierrc.js or prettier.config.js
module.exports = {
  plugins: [require('prettier-plugin-tailwindcss')],
}

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: image

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.

["INFO" - 9:13:23 PM] Using config file at 'c:\Users\<user>\OneDrive\Desktop\<project>\.prettierrc'
["INFO" - 9:13:51 PM] Formatting file:///c%3A/Users/<user>/OneDrive/Desktop/<project>/.prettierrc

For additional context:

pnpm -v
8.6.3

.prettierrc

{
    "plugins": ["node_modules/prettier-plugin-jsdoc"] 
    // also tried with just "prettier-plugin-jsdoc" and require and require.resolve
}

@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 covers vscode as well. Hope that helps.

Thanks everyone for the update! I’ll close this issue as it was specific to automatically loading prettier plugins with pnpm and it’s no longer relevant to have it opened as this feature is being removed.

I’ve been loading prettier plugins with pnpm manually for a while now and it works fine. For anyone still facing issues loading prettier plugins manually, please feel free to open an issue on prettier repo if there’s no issue opened already.

Here’s the config I’m using currently:

// .prettierrc.js

module.exports = {
  arrowParens: 'always',
  printWidth: 120,
  semi: false,
  singleQuote: true,
  tabWidth: 2,
  trailingComma: 'all',
  useTabs: false,
  plugins: ['prettier-plugin-tailwindcss'],
}

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 with prettier and prettier-plugin-tailwindcss with a manual configuration step for prettier.

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 where prettier binary is executed and that works with npm. It’s supposed to work with pnpm too after hoisting but it doesn’t for some reason. I don’t know if it’s related to symlinking or because even after hoisting prettier still executes from node_modules/.pnpm.

When I just replaced the node_modules/prettier installed with pnpm with another installed with npm it worked as expected.