Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier stops working when installing the plugin #29

Open
angelmtztrc opened this issue Apr 11, 2021 · 7 comments
Open

Prettier stops working when installing the plugin #29

angelmtztrc opened this issue Apr 11, 2021 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@angelmtztrc
Copy link

Describe the bug
When installing the plugin, Prettier stops working. It had never happened to me before, today I decided to create a NextJS project and when I added prettier next to the plugin, the code formatting stopped working completely.

To Reproduce
Steps to reproduce the behaviour:

  1. Install Prettier
  2. Install prettier-plugin-tailwind
  3. Press CTRL + S and format on save doesn't work

Expected behaviour
I expect to "format" the code on save, but this doesn't work. I already tested in other projects and works just fine.

Versions:

  • prettier-plugin-tailwind version: 2.2.10
  • Operating system: Ubuntu 20.04
  • NPM/Yarn version: Yarn v1.22.10
@angelmtztrc angelmtztrc added the bug Something isn't working label Apr 11, 2021
@lkbr
Copy link

lkbr commented Apr 11, 2021

Its likely due to the new utilities introduced in https://github.com/tailwindlabs/tailwindcss/releases/tag/v2.1.0

@thebuilder
Copy link
Contributor

See tqwewe/tailwind-classes-sorter#4

A fix is to disable JIT for formatting, by changing the tailwind.config.js:

module.exports = {
  // This "hack" ensures your IDE detects all normal Tailwind classes, while JIT is used when compiling the project.
  // All the normal Tailwind classes should show up in code completion. It can't show all the new classes generated by JIT.
  mode: process.env.NODE_ENV ? 'jit' : undefined,
};

@LeoniePhiline
Copy link

LeoniePhiline commented May 19, 2021

For the Googlers out there:


✖ prettier -w -u:
/project-path/node_modules/tailwindcss/lib/plugins/backdropBlur.js:26
      matchUtilities({
      ^

TypeError: matchUtilities is not a function
    at /project-path/node_modules/tailwindcss/lib/plugins/backdropBlur.js:26:7
    at /project-path/node_modules/tailwindcss/lib/util/processPlugins.js:69:5
    at Array.forEach (<anonymous>)
    at TWClassesSorter._default [as processPlugins] (/project-path/node_modules/tailwindcss/lib/util/processPlugins.js:63:11)
    at /project-path/node_modules/tailwind-classes-sorter/lib/index.js:179:52
    at Array.forEach (<anonymous>)
    at TWClassesSorter.getAllSelectors (/project-path/node_modules/tailwind-classes-sorter/lib/index.js:167:14)
    at new TWClassesSorter (/project-path/node_modules/tailwind-classes-sorter/lib/index.js:47:37)
    at Object.<anonymous> (/project-path/node_modules/prettier-plugin-tailwind/lib/index.js:10:25)
    at Module._compile (node:internal/modules/cjs/loader:1109:14)

If you experience this symptom, take the above medicine.

  mode: process.env.NODE_ENV
    ? // JIT for `npm run dev`.
      'jit'
    : // No JIT for IDE class and generation & prettier runs.
      undefined,

@alexcroox
Copy link

alexcroox commented Jun 2, 2021

This fix doesn't work in a number of scenarios, especially when using eslint with prettier either via cli or vscode extension. The matchUtilities is not a function error is triggered in both contexts.

@thebuilder
Copy link
Contributor

I'd recommend switching to https://github.com/francoismassart/eslint-plugin-tailwindcss with --fix to handle the sorting.
It handles jit mode perfectly.

To keep IDE code completion working with, I still include the NODE_ENV toggle above, but set jit on Tailwind inside .eslintrc.js:

const tailwindConfig = require('./tailwind.config');
tailwindConfig.mode = 'jit';

module.exports = {
  // Rest of config is omitted
  rules: {    
    'tailwindcss/classnames-order': 'warn',
    'tailwindcss/no-custom-classname': 'warn',
    'tailwindcss/no-contradicting-classname': 'error',
  }
  settings: {
    tailwindcss: {
      config: tailwindConfig,
      whitelist: customTailwindClasses,
    },
  },
}

@alexcroox
Copy link

alexcroox commented Jun 2, 2021

Thanks, I did give that eslint-plugin-tailwindcss a go this morning but it's very slow and I have a post-commit hook to run the linter and it added about 30 seconds to my commit times on a not-yet-huge project so was a no go on anything other than a trivial project.

@ndom91
Copy link

ndom91 commented Jun 12, 2021

Having this same issue. Just disabled jit mode for now as this was in a relatively small and new toy project as well, but obviously down the line it'd be nice to have this plugin and tailwind jit working nicely together.

Anything we can do to help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants