-
Notifications
You must be signed in to change notification settings - Fork 216
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
Exporting as ES Module Syntax (ESM) #194
Comments
This module used to expose a Since so many people use Webpack, which is broken, it wasn't worth the support load to expose both entry points. However, like you, I find myself often wanting to include modules directly in the browser... maybe the way forward is to publish a CommonJS-only package for Webpack users, and change this package back to exposing both ESM and CJS for everyone else. |
with the node 12+ now supporting exports in the https://nodejs.org/api/esm.html#esm_conditional_exports could be something like this
thing is it would require a build/copy of the code as esm for the browser needs to be "pure" esm...
so esm/require would load 2 different files... but as it's a "pure" function that should not be an issue... if you think that makes sense then I can look into a Pull Request |
I'm open to adding the |
Only use "exports": {
"require": "./index.cjs",
"default": "./index.mjs"
},
"main": "./index.cjs", |
But then Rollup and native browser consumers wouldn't be able to consume the ESM module (which is the whole point of this issue per the original post) |
Hmm, I thought rollup and the likes would be supporting "exports" but after looking it it seems they're not. Well it would still be good for this package to support "exports" for when it becomes more supported by bundlers. I guess once webpack sorts itself out, the "module" field can be added. |
Hi. Just wanted to weigh in that I'm hitting this issue now and I think it's completely reasonable to split off a cjs version of this that webpack users can use until there's enough pressure on webpack to fix it. In the meantime, is there any workaround for this? |
I think we're far enough along now with exports (package entrypoints) that all modern tools, bundlers, typescript, etc. etc. support it. So can we do "main" + "exports" field now to support CJS + ESM? |
@TehShrike, @jorenbroekema speaks the truth. people who rely on this package dont really want to switch (btroncone/ngrx-store-localstorage#229) and web-pack 5 has been out for a while, we should get esm packages, there are two tickets open about it, this one and #250 |
https://www.npmjs.com/package/@bundled-es-modules/deepmerge feel free to use ESM bundled fork of this project. I felt I had no choice but to do this, since the author seems reluctant to add ESM-first support, and deepmerge-ts is almost 4 times as large as original deepmerge.. Of course, you can also commit yourself to a compile-step like @rollup/plugin-commonjs or webpack/esbuild equivalent but for projects that are otherwise compile-step-free, that's not a great option either. I will deprecate my fork as soon as the author of this package publishes an ESM version. |
Please, export
"module"
entry point in thepackage.json
as ES Module Syntax (ESM).I would like to be able to use it directly in the browser, without any build/bundle process.
The text was updated successfully, but these errors were encountered: