-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix esm compatibility for @headlessui/tailwindcss plugin package #3051
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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! |
This is also preventing me from installing. A merge would be much appreciated. |
@dawnmist 👏🏿 👏🏿 👏🏿 |
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.
Hey! This shouldn't be necessary and there are probably issues with the tools handling the imports. That said, this PR doesn't break things and if they help with your setup then let's merge it! Note: if you are using Headless UI v2 (React), then we consider this package as deprecated and prefer to use
Our docs also show these new data attributes. E.g.: https://headlessui.com/react/menu#using-data-attributes Thanks for the PR! |
c4f0c42
to
df39a64
Compare
I also published a new patch version that includes this change: https://www.npmjs.com/package/@headlessui/tailwindcss/v/0.2.1 You can install it using: |
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 scriptscripts/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 astailwindcss/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).