atomiks / floating-ui

JavaScript positioning library for tooltips, popovers, dropdowns, and more

Home Page:https://floating-ui.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ESM: type: "module" in package.json?

jpzwarte opened this issue · comments

If @floating-ui/dom is meant to be ESM, then shouldn't it have "type": "module" in package.json? Also an exports section?

I'd like for it to be but I want to make sure there are no issues with bundlers like webpack/create-react-app. I changed it back to a "legacy" type of ESM using a plain .js file + module field to ensure this, for now. Wondering what the best way to go about this is? See #2

I believe you can support both, see https://nodejs.org/api/packages.html#packagejson-and-file-extensions

// package.json
{
  "main": "./main-require.cjs",
  "exports": {
    "import": "./main-module.js",
    "require": "./main-require.cjs"
  },
  "type": "module"
}

Also, this looks interesting: https://antfu.me/posts/publish-esm-and-cjs

Will give that a go and manually test the package in CRA to make sure there are no issues! I know that Nuxt 3 requires this type of setup going forward, so definitely something to move toward. Evidently it seems like using .mjs is not the way to do it though due to the current issues with bundlers.

My 2 cents: I would go with an ESM default (so .js instead of .mjs) and provide an explicit require export with .cjs. Assuming that is compatible with CRA etc.