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

Use .mjs extension for ESM build. #155

Closed
jgerigmeyer opened this issue Jun 23, 2022 · 3 comments
Closed

Use .mjs extension for ESM build. #155

jgerigmeyer opened this issue Jun 23, 2022 · 3 comments

Comments

@jgerigmeyer
Copy link
Member

jgerigmeyer commented Jun 23, 2022

Build tools that use native ESM (e.g. Vite) expect ESM builds to use the .mjs extension (unless the nearest package.json has "type": "module", in which case CJS builds should use the .cjs extension).

See: https://nodejs.org/api/packages.html#determining-module-system

Currently, both the ESM and CJS builds use .js -- this causes Node to assume they are both CJS:

Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

Would you be willing to consider either adding "type": "module" to your package.json file, or renaming the built packages to e.g. color.esm.mjs and color.cjs.js?

@LeaVerou
Copy link
Member

Thank you for pointing that out! I just pushed a fix that:

  • Renames CJS exports to use .cjs
  • Adds type: "module" to package.json
  • Makes color.js be the ESM version (IIFE is now color.iife.js)

Let me know if that fixes it!

@jgerigmeyer
Copy link
Member Author

Let me know if that fixes it!

Works for me, testing locally! I noted a few minor issues:

  1. It looks like the main and module paths in package.json need to be updated to the newer build.
  2. You may run into trouble compiling the 11ty site with "type": "module" set. Looks like you already solved this 🎉
  3. Similarly, I think postcss.config.js needs to be renamed to .cjs for npm run build:css to work.

@LeaVerou
Copy link
Member

Let me know if that fixes it!

Works for me, testing locally! I noted a few minor issues:

  1. It looks like the main and module paths in package.json need to be updated to the newer build.
  2. You may run into trouble compiling the 11ty site with "type": "module" set. Looks like you already solved this 🎉
  3. Similarly, I think postcss.config.js needs to be renamed to .cjs for npm run build:css to work.

I forgot to post yesterday, all of these should be fixed now!

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