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

Fix esm compatibility for @headlessui/tailwindcss plugin package #3051

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dawnmist
Copy link

Currently the @headlessui/tailwindcss package throws errors when imported into an esm project, stating that imports are not permitted inside commonjs files, as documented in the discussion threads:

The current @headlessui/tailwindcss npm package distributes its files using the convention .js = esm, .cjs = commonjs. For node/compilers to properly treat the .js files as esm, the package.json needs to also specify that the package "type" is "module". Files ending in .cjs will continue to be treated as commonjs files with that setting. The build script scripts/fix-types.js needed to be renamed to use the .cjs extension so that it continued to be treated as a commonjs script after the package's type was set to module.

When an esm file imports another file, it needs to specify the full filename with extension, so the import of the tailwindcss/plugin in src/index.ts needed to be specified as tailwindcss/plugin.js. Typescript won't automatically add the extension if it was not present when creating the compiled version, so this needed to be specified in the source for it to be present in the distributed version (otherwise it throws file not found errors).

The distributed tailwindcss plugin package uses `.js` for esm files, and `.cjs` for commonjs files. This corresponds to `"type": "module"` in the package.json file.

One build script `fix-types.js` was a commonjs script which was breaking this module file naming pattern. Renamed the script to `fix-types.cjs` so that we could then standardise the module type for @headlessui/tailwindcss package as a whole.
ESM imports need to specify the filename extension when importing individual files.
Copy link

vercel bot commented Mar 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
headlessui-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 11:37am
headlessui-vue ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 11:37am

@robertotcestari
Copy link

Guys, can we merge this?

This is preventing me migrating my Remix app to Vite as this plugin won't work because of ESM compatibility.

thanks!

@bcliffor
Copy link

bcliffor commented May 2, 2024

This is also preventing me from installing. A merge would be much appreciated.

@nyedidikeke
Copy link

@dawnmist 👏🏿 👏🏿 👏🏿
@RobinMalfait Can you assist review and merge, please?

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

Successfully merging this pull request may close these issues.

None yet

4 participants