lucide icon indicating copy to clipboard operation
lucide copied to clipboard

Generate ESM/CJS variants of `dynamicIconImports`

Open dan-lee opened this issue 5 months ago • 1 comments

Probably fixes #2366

What is the purpose of this pull request?

  • [ ] New Icon
  • [x] Bug fix
  • [ ] New Feature
  • [ ] Documentation update
  • [ ] Other:

Description

When trying to bundle my library with an import of dynamicIconImports:

import dynamicIconImports from "lucide-react/dynamicIconImports.js";

I get this error:

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

export { dynamicIconImports as default };
^^^^^^

SyntaxError: Unexpected token 'export'

I think there are 3 options to solve this:

  1. Set the "type": "module" in the package.json
  2. Use .mjs as extension
  3. Add conditional exports

I chose the second option for simplicity and now it creates two separate files for CJS and ESM. Let me know if there are concerns. I tried to rename the file locally to .mjs which resolved the error.

Before Submitting

  • [x] I've read the Contribution Guidelines.
  • [x] I've checked if there was an existing PR that solves the same issue.

dan-lee avatar Sep 06 '24 08:09 dan-lee