nextui-org / tailwind-variants

🦄 Tailwindcss first-class variant API
https://tailwind-variants.org
MIT License
2.42k stars 70 forks source link

Type error on build after upgrading to v0.2 #181

Open josantana opened 7 months ago

josantana commented 7 months ago

Describe the bug After upgrading to v0.2.1, I got the following error message when trying to build some of the components I'm developing:

error TS2742: The inferred type of 'buttonStyles' cannot be named without a reference to '.pnpm/tailwind-merge@2.2.2/node_modules/tailwind-merge'. This is likely not portable. A type annotation is necessary.
error TS2742: The inferred type of 'buttonStyles' cannot be named without a reference to '@/components/button/node_modules/tailwind-variants/dist/config'. This is likely not portable. A type annotation is necessary.
error TS2742: The inferred type of 'buttonStyles' cannot be named without a reference to '@/components/button/node_modules/tailwind-variants/dist'. This is likely not portable. A type annotation is necessary.

These three messages repeats several times when I run the build command.

To Reproduce Here it is my scenario:

// From packages/components/button.styles.tsx
import { tv } from "tailwind-variants";
export const buttonStyles = tv({ slots: { base: "..." }, ... });

// From packages/components/pagination.tsx
import { buttonStyles } from "@/components/button/button.styles";

const { base } = buttonStyles({ ... });

Above, I'm importing the Button styles to reuse on the Pagination component. That's what started it all. After that, I got some inconsistent build behavior even from the simple usage of tv inside a single package. The error occurs when tsup is building DTS files.

I'm working on a monorepo, using PNPM as package manager and tsup to build the package. I've tried to clean up PNPM's cache and tweak some tsconfig configs, with no success. The only stable solution I got was to rollback Tailwind Variants to v0.1.2.

This is likely related to the move to Tailwind Merge 2.2.0 on version ^0.2. But I'm not certain exactly why.

Expected behavior Expected it to just work, like it did on version ^0.1 so I can keep my project up-to-date with its dependencies.

mskelton commented 7 months ago

@josantana Do you have tailwind-merge installed in your project separately from tailwind-variants?

douglasgomes98 commented 1 month ago

@mskelton here same scenario, and I also have tailwind-merge installed in another package