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

ESM & CJS support for Rollup Plugin #451

Open
VojGin opened this issue Feb 14, 2024 · 6 comments · May be fixed by #538
Open

ESM & CJS support for Rollup Plugin #451

VojGin opened this issue Feb 14, 2024 · 6 comments · May be fixed by #538
Labels
enhancement New feature or request

Comments

@VojGin
Copy link

VojGin commented Feb 14, 2024

Describe the feature request

StyleX (all of the packages, including plugins) is written and build as ES Module. So it can be easily imported to any ESM compatible project. But not all of the packages have support for CommonJS and it's currently impossible to import it into a CJS project. Can we have also CJS build support for all packages?

To give you an example. NX rollup executor configuration currently does not support ESM. This means StyleX currently can't be used in NX monorepo projects using rollup builder. (See this). The reason is that stylexjs/rollup-plugin does not support cjs.

@VojGin VojGin added the enhancement New feature or request label Feb 14, 2024
@nmn
Copy link
Contributor

nmn commented Feb 15, 2024

The stylex package already has both ESM and CJS exports. The build script generates both variants of the package and the package.json has been configured to support both kinds of module systems. There is likely an issue with your Nx configuration as Rollup likes to import ESM when possible.

That is the only package that needs to be bundled as every other package is a plugin for Babel, ESLint or some bundler.

@nmn nmn closed this as completed Feb 15, 2024
@VojGin
Copy link
Author

VojGin commented Feb 15, 2024

@nmn Thanks for the reply. I probably expressed myself incorrenctly.

What you are saying is true. The stylex package indeed supports both esm and cjs.

But in my original post I mention (all of the packages). Meaning all of the monorepo packages such as plugins. For example the rollup-plugin does not support cjs. And that's the issue I'm trying to raise here.

@nmn nmn changed the title Can we have both ESM & CJS support? ESM & CJS support for Rollup Plugin Feb 15, 2024
@nmn nmn reopened this Feb 15, 2024
@nmn
Copy link
Contributor

nmn commented Feb 15, 2024

My understanding was that Rollup was all-in on ESM, so only exporting an ESM build was intentional. This is also the case for the Babel and ESlint plugins which need to be CJS to work.

We can probably add CJS support the rollup plugin without too much trouble.

@VojGin
Copy link
Author

VojGin commented Feb 15, 2024

That would be brilliant. I don’t think the support for cjs should bring any hassle in the long run. Although we may hopefully see a future with single united module philosophy. 🙂

@VojGin
Copy link
Author

VojGin commented Mar 8, 2024

Hey @nmn, is the support planned on any roadmap? Can I help with this anyhow? Thanks! 🙏

@nmn
Copy link
Contributor

nmn commented Mar 12, 2024

@VojGin Happy to accept a PR as I haven't had the time to prioritize this yet. The @stylexjs/stylex package is a good example to use.

@VojGin VojGin linked a pull request Apr 14, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants