Fix esm compatibility for @headlessui/tailwindcss plugin package #3051
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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).