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

Cannot build plugin: types in tailwindcss/plugin are broken #15844

Open
cyberalien opened this issue Jan 25, 2025 · 4 comments
Open

Cannot build plugin: types in tailwindcss/plugin are broken #15844

cyberalien opened this issue Jan 25, 2025 · 4 comments

Comments

@cyberalien
Copy link

cyberalien commented Jan 25, 2025

What version of Tailwind CSS are you using?

4.0.0

What build tool (or framework if it abstracts the build tool) are you using?

typescript: 5.7.2

What version of Node.js are you using?

20.14.0

What operating system are you using?

macOS 15.2

Reproduction URL

https://github.com/cyberalien/tailwind-plugin-bug

Describe your issue

Reproduction includes a very basic plugin:

import plugin from 'tailwindcss/plugin';

const exportedPlugin = plugin(() => {
	return ({ matchComponents }) => {
		matchComponents({
			test: (content: string) => {
				return {
					color: content,
				};
			},
		});
	};
});

export default exportedPlugin;

On line 3 TypeScript throws the following error:

src/plugin.ts:3:7 - error TS2742: The inferred type of 'exportedPlugin' cannot be named without a reference to '../node_modules/tailwindcss/dist/types-BTRmm49E.mjs'. This is likely not portable. A type annotation is necessary.

3 const exportedPlugin = plugin(() => {
        ~~~~~~~~~~~~~~

Building it using tsc -b.

Removed all unnecessary dependencies and packages to show smallest possible reproduction.

@cyberalien
Copy link
Author

Changed reproduction URL to a smaller reproduction without monorepo setup.

@rijenkii
Copy link

rijenkii commented Jan 25, 2025

Think this is a TS problem (feature?) rather than tailwind, see possible workarounds: microsoft/TypeScript#47663 (comment)

Specifically, this seems to work:

 import plugin from 'tailwindcss/plugin';

-const exportedPlugin = plugin(() => {
+const exportedPlugin: ReturnType<typeof plugin> = plugin(() => {
 	return ({ matchComponents }) => {
 		matchComponents({
 			test: (content: string) => {
 				return {
 					color: content,
 				};
 			},
 		});
 	};
 });

export default exportedPlugin;
rijenkii@rijenkiipc /t/tailwind-plugin-bug ((no description set) r b (empty))
> npm run build

> @iconify/[email protected] build
> tsc -b

rijenkii@rijenkiipc /t/tailwind-plugin-bug ((no description set) r b (empty))
> cat lib/plugin.d.ts
import plugin from 'tailwindcss/plugin';
declare const exportedPlugin: ReturnType<typeof plugin>;
export default exportedPlugin;

@cyberalien
Copy link
Author

Proper solution is to export types PluginWithConfig and PluginWithOptions in plugin.d.ts and plugin.d.mts.

@cyberalien
Copy link
Author

Fixed in #15869

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