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

ts-to-zod is using Prettier v2 which autoloads configs and causes errors due to unsupported plugins #158

Closed
martitv opened this issue Sep 19, 2023 · 2 comments

Comments

@martitv
Copy link

martitv commented Sep 19, 2023

Bug description

Ref this issue: #tailwindlabs/prettier-plugin-tailwindcss#214

Hey! Thanks for that repo. The problem is definitely that ts-to-zod is using Prettier 2 to do some formatting internally, we only support Prettier v3, and they're both using your config file (plus Prettier v2 autoloads plugins by default so even without the config it'd still break):

Screenshot 2023-09-19 at 09 14 22 Screenshot 2023-09-19 at 09 14 34
That said, I did figure out a workaround but it requires a super strange setup for the config to stop v2 from loading prettier-plugin-tailwindcss while still allowing ts-to-zod to use Prettier and your config.

You'll want to customize your prettier config such that:

  • Prettier v2 autoloading is disabled — otherwise the plugin will always be picked up because of the package name and you'll keep getting the error
  • Configure Prettier to only load the plugin for files matching app/*. You do this via the overrides key in your config.

This setup looks like this:

/** @type {import('prettier').Config} */
module.exports = {
  // Stop autoloading in Prettier v2
  // This is a warning in Prettier v3
  // but you can safely ignore it
  pluginSearchDirs: [],

  overrides: [
    // Only load `prettier-plugin-tailwindcss` when scanning the app dir
    // This _should_ work so long as `ts-to-zod` doesn't run prettier on any files in `app/*`
    {
      files: ["app/*"],
      options: {
        plugins: ["prettier-plugin-tailwindcss"],
      },
    },
  ],
};

So, unfortunately nothing we can do to fix this on our end but the above Prettier config might fix things for you. Hope that helps! ✨

Versions

  • Typescript: v5.1.6
  • Zod: v3.1.3
@martitv martitv changed the title ts-to-zod is unsing Prettier v2 which autoloads configs and causes errors due to unsupported plugins ts-to-zod is using Prettier v2 which autoloads configs and causes errors due to unsupported plugins Sep 19, 2023
@martitv
Copy link
Author

martitv commented Sep 28, 2023

Bump!
Prettier-plugin-tailwindcss is a super important plugin for using tailwind! Please fix this so it is possible to use both of these libraries at the same time!

@schiller-manuel
Copy link
Collaborator

#169 fixes this

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

2 participants