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

Plugin is incompatible with Prettier v3.0 #176

Closed
rahmat-dev opened this issue Jul 5, 2023 · 45 comments
Closed

Plugin is incompatible with Prettier v3.0 #176

rahmat-dev opened this issue Jul 5, 2023 · 45 comments
Assignees

Comments

@rahmat-dev
Copy link

What version of prettier-plugin-tailwindcss are you using?
v0.3.0

What version of Tailwind CSS are you using?
v3.3.2

What version of Node.js are you using?
v18.16.0

What package manager are you using?
npm

What operating system are you using?
macOS

Describe your issue

I've installed tailwindcss, prettier and prettier-plugin-tailwindcss in my new next js app. But the class is not sorting when I save the file.
image

I found this error on the vs code logs output
image

@lunacd
Copy link

lunacd commented Jul 5, 2023

Same issue here after upgrading to prettier 3.0

@thevuong
Copy link

thevuong commented Jul 5, 2023

It seems that you are currently utilizing prettier version 3.0.0. Please consider a temporary downgrade to version 2.8.8.

@thecrypticace thecrypticace self-assigned this Jul 5, 2023
@thecrypticace
Copy link
Contributor

Hey! For now we'd recommend downgrading to v2.8. Prettier v3.0 has some API changes that'll require a good bit of work and testing for our plugin. But it's on our radar! I'm going to be looking into this later this week or early next week.

@thecrypticace thecrypticace changed the title tailwind class not sorting Plugin is incompatible with Prettier v3.0 Jul 5, 2023
@rahmat-dev
Copy link
Author

thanks for the information @thevuong @thecrypticace

@SolomonLake
Copy link

Thanks for the update! We'll stay on 2.8.8 for now. Thanks for your work @thecrypticace.

@debashisbiswas
Copy link

While we're at it, I also noticed that prettier recently removed plugin autoloading (prettier/prettier#14759) in version 3.0.0, breaking configurations that rely on autoloading as the docs for this plugin recommend.

@thecrypticace
Copy link
Contributor

thecrypticace commented Jul 6, 2023

@debashisbiswas The docs for this plugin explicitly recommended against autoloading and gave instructions for disabling it (when using it in conjunction with any other "compatible" plugin).

We'll update the docs to remove any mention of autoloading once we've updated for v3.0.

@PaulGriz
Copy link

PaulGriz commented Jul 6, 2023

Node.js Version: v18.16.0
Package Manager: npm
Operating System: macOS


Here to confirm that rolling back to prettier v2.8 resolved the issue. Commands used:

  1. npm uninstall prettier prettier-plugin-tailwindcss
  2. npm install -D prettier@2.8 prettier-plugin-tailwindcss

@ndelanhese
Copy link

Same issue here

@mutheusalmeida
Copy link

Hi, guys. I downgraded and it's still not working. My .prettierrc using Vite:

Screenshot (441)

@ndelanhese
Copy link

After downgrade, it`s works fine for me

@DitwanP
Copy link

DitwanP commented Jul 7, 2023

@mutheusalmeida

Hi, guys. I downgraded and it's still not working. My .prettierrc using Vite:

I don't know if this will work for you but after downgrading I had to reload my vscode for it to start working for me. I'm not using a .prettierrc file though. I'm just using the prettier extension.

@devloos
Copy link

devloos commented Jul 7, 2023

Thanks @thecrypticace I'm looking forward to it

@mutheusalmeida downgrading worked just fine maybe try @DitwanP

@stabildev
Copy link

Spent 3 hours on this (first time installation and first time prettier config). Works after downgrade. Thought I was losing my mind

@verheyenkoen
Copy link

Spent 3 hours on this (first time installation and first time prettier config). Works after downgrade. Thought I was losing my mind

@stabildev Yeah didn't work for me either just by downgrading prettier. Had to uninstall both packages and then install them again (and I guess reloading the vscode window).

@mutheusalmeida
Copy link

Spent 3 hours on this (first time installation and first time prettier config). Works after downgrade. Thought I was losing my mind

@stabildev Yeah didn't work for me either just by downgrading prettier. Had to uninstall both packages and then install them again (and I guess reloading the vscode window).

It didn't work for me.

@SolomonLake
Copy link

For folks using vs code that are still having issues with version 2.8.8, you could try installing the specific Prettier extension version 9.13.0. I've found some backwards compatibility issues with the latest extension version. https://marketplace.visualstudio.com/items/esbenp.prettier-vscode/changelog

@gyhyfj
Copy link

gyhyfj commented Jul 8, 2023

same problem

@thecrypticace
Copy link
Contributor

Hey all! We've just released v0.4.0 with support for both Prettier v2.x and v3.0.

Please note that many plugins have yet to be updated for Prettier v3 so the third-party plugin compatibility has been temporarily disabled when using Prettier v3. Once plugins start migrating we will test them and do another release that implements compatibility with working third-party plugins where possible.

So, for example, Svelte, Twig (Melody), Pug, Astro, etc… are not currently supported. We'll be keeping an eye on the plugins once they've updated and work toward another release which re-enables support.

Please give the new version a test and open a new issue if you see any problems. Thanks for your patience! ✨

@thecrypticace
Copy link
Contributor

@vighnesh153 I'm pretty sure this is a change in Prettier itself rather than with our plugin. It may be related to the removal of plugin autoloading in Prettier v3 which means that you may need to specify the full path to the plugin.

@michaelhays
Copy link

All working for me 👍

Thanks so much for the quick turnaround!

@emonno13
Copy link

emonno13 commented Jul 20, 2023

You dont need to downgrade, just add this line "plugins": ["prettier-plugin-tailwindcss"] to .prettierrc.json

Screenshot 2023-07-20 at 23 33 17

@martinharyanto
Copy link

Just leaving a comment here, for me this is still not working

  • "react": "^18.2.0"
  • "postcss": "^8.4.21"
  • "autoprefixer": "^10.4.14"
  • "tailwindcss": "^3.2.7"

devDep:

  • "vite": "^4.2.0"
  • "prettier": "3.0" & "prettier": "2.8"
  • "prettier-plugin-tailwindcss": "0.4.1"

tailwind.config.cjs

module.exports = {
	content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
	plugins: [],
};

prettier.config.js

module.exports = {
  plugins: [require('prettier-plugin-tailwindcss')],
}

Not sure what is wrong, I tried both v3 and v2.8 for prettier but still not working. when saving it wont format the classes.
Sorry if this has been resolved with workaround, but I can't seem to find the solution

@hazlema
Copy link

hazlema commented Jul 21, 2023

You dont need to downgrade, just add this line "plugins": ["prettier-plugin-tailwindcss"] to .prettierrc.json

Screenshot 2023-07-20 at 23 33 17

Works for me!

@vectorcr
Copy link

You dont need to downgrade, just add this line "plugins": ["prettier-plugin-tailwindcss"] to .prettierrc.json
Screenshot 2023-07-20 at 23 33 17

Works for me!

Thanks for the assist! I was running into the same issue and your solution fixed it for me.

@aronmal
Copy link

aronmal commented Jul 24, 2023

prettier.config.js

module.exports = {
  plugins: [require('prettier-plugin-tailwindcss')],
}

@martinharyanto Without the require()

It is not a workaround, it it the new way to implement. Cause is the removed plugin autoloading in prettier v3 because of problems with package managers except npm.

@sy4578
Copy link

sy4578 commented Jul 24, 2023

not working with above all commented pattern

@ronaldtveen
Copy link

ronaldtveen commented Jul 25, 2023

Took me way too long to get this to work, getting confused by the comments above... It was actually very simple and straight forward to get it to work with the 3.x branch of prettier. This is what worked for me:

  1. npm install -D prettier prettier-plugin-tailwindcss
    At the moment of writing
    • prettier v3.0.0
    • prettier-plugin-tailwindcss v0.4.1
  2. Then in .prettierrc.json
{
  "semi": false,
  "tabWidth": 2,
  // [..]
  "plugins": ["prettier-plugin-tailwindcss"]
}

@stabildev
Copy link

Yes, it's working now and the issue is fixed

@jesusvallez
Copy link

jesusvallez commented Jul 30, 2023

You dont need to downgrade, just add this line "plugins": ["prettier-plugin-tailwindcss"] to .prettierrc.json

Screenshot 2023-07-20 at 23 33 17

In a JS file also works .prettierrc.js

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

@mutheusalmeida
Copy link

You dont need to downgrade, just add this line "plugins": ["prettier-plugin-tailwindcss"] to .prettierrc.json
Screenshot 2023-07-20 at 23 33 17

In a JS file also works .prettierrc.js

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

It just works with a .json file. Anyone know whats the matter?

@jesusvallez
Copy link

@mutheusalmeida as I said, it works for me in a js. Maybe you are missing some extra configuration in your project.

These are my prettier and eslint dependencies in case it can help you:

    "eslint": "8.46.0",
    "eslint-config-prettier": "8.9.0",
    "eslint-config-standard": "17.1.0",
    "eslint-config-standard-typescript-prettier": "6.0.0",
    "eslint-plugin-import": "2.28.0",
    "eslint-plugin-n": "15.7.0",
    "eslint-plugin-node": "11.1.0",
    "eslint-plugin-prettier": "4.2.1",
    "eslint-plugin-promise": "6.1.1",
    "eslint-plugin-unused-imports": "2.0.0",
    "prettier": "2.8.8",
    "prettier-plugin-tailwindcss": "0.4.1",

and this is my .eslintrc.js file

const config = require('eslint-config-standard-typescript-prettier')

module.exports = {
  ...config,
  ignorePatterns: ['*.js', 'vite.config.ts'],
  plugins: ['unused-imports'],
  parserOptions: { project: './tsconfig.json' },
  rules: {
    ...config.rules,
    '@typescript-eslint/no-explicit-any': 'error',
    '@typescript-eslint/no-empty-function': [
      'error',
      { allow: ['arrowFunctions'] },
    ],
    'no-unused-vars': 'off',
    'unused-imports/no-unused-imports': 'error',
    'unused-imports/no-unused-vars': [
      'warn',
      {
        vars: 'all',
        varsIgnorePattern: '^_',
        args: 'after-used',
        argsIgnorePattern: '^_',
      },
    ],
  },
}

@akomm
Copy link

akomm commented Oct 2, 2023

I understand that the issue with changes in the prettier v3 API requires a lot of changes.

What I don't quite understand is why this issue is closed. Its more likely people will open new because they don't find an open issue related to their problem.

@FinnDore
Copy link

FinnDore commented Oct 2, 2023

Because it's fixed!

@akomm
Copy link

akomm commented Oct 2, 2023

Because it's fixed!

I have:

"prettier": "3.0.3",
"prettier-plugin-tailwindcss": "0.5.4"

My bad, its probably the vscode tailwind extension issue, because it does not automatically pick up the plugin anymore, so I have to add it to .prettierrc.json explicitly.

I think its a good idea to do it anyway, but before I had it in the short syntax with the prefix convention ("tailwindcss" instead of "prettier-plugin-tailwindcss"). Changing it now to the full package name fixed it.

@aronmal
Copy link

aronmal commented Oct 2, 2023

My bad, its probably the vscode tailwind extension issue, because it does not automatically pick up the plugin anymore, so I have to add it to .prettierrc.json explicitly.

The plugin search feature has been removed.

@ssalib-aamc
Copy link

ssalib-aamc commented Jan 10, 2024

I installed "prettier-plugin-tailwindcss": "0.4.1", instead of "prettier-plugin-tailwindcss": "^0.5.10",. Restarted VS Code and it worked.

@dinakar17
Copy link

dinakar17 commented May 19, 2024

I've uninstalled both prettier and prettier-plugin-tailwindcss (after installing them separately) and installed them together. Now all of a sudden it's working. I don't know why and how (I haven't restarted the VSCode Terminal)

There are two areas you need to check

package.json
image

.prettierrc

image

@Fred-O-Nyarko
Copy link

Fred-O-Nyarko commented Jun 13, 2024

I went nuts on this.
NB: you don't have to downgrade your prettier.
These are my steps. (you can go manual or automate this)

  1. Delete the plugins line
  2. Run openapi codegen
  3. Add the plugins line back

My package.json

  "scripts": {
    "dev": "vite",
    "build": "tsc && vite build",
    "codegen": "node generateApiCode.js",
    "format": "prettier --write \"**/*.{ts,tsx,md}\"",
    "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
    "preview": "vite preview",
    "prepare": "husky"
  },

generateApiCode.js

import { execSync } from "child_process";
import pkg from "fs-extra";

const { readFileSync, writeFileSync } = pkg;

const configFilePath = ".prettierrc";
const lineToRemove =
    '"plugins": ["@trivago/prettier-plugin-sort-imports","prettier-plugin-tailwindcss"],';

// Step 1: Read the file
const fileContent = readFileSync(configFilePath, "utf8");

// Step 2: Remove the specified line
const modifiedContent = fileContent
    .split("\n")
    .filter((line) => !line.includes(lineToRemove))
    .join("\n");

// Step 3: Write the modified content back to the file
writeFileSync(configFilePath, modifiedContent, "utf8");

// Step 4: Run the desired command (e.g., "your-command")
// Note: Replace 'your-command' with the actual command you want to run
try {
    execSync("npx @rtk-query/codegen-openapi src/redux/api/openapi-config.ts", {
        stdio: "inherit",
    });
} catch (error) {
    console.error("Error executing command:", error);
}

// Step 5: Add the original file contents
writeFileSync(configFilePath, fileContent, "utf8");

my .prettierrc file
{ "plugins": ["@trivago/prettier-plugin-sort-imports","prettier-plugin-tailwindcss"], "tailwindFunctions": ["clsx", "tw"] }
and finally I ignore .prettierrc in my .prettierignore file, so my script will work well as expected.

This is not the best solution, but it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests