epoberezkin / fast-json-stable-stringify

Deterministic JSON.stringify() - a faster version of @substack's json-stable-strigify without jsonify.
Other
285 stars 34 forks source link

Exporting as ES Module Syntax (ESM) #8

Open abdonrd opened 5 years ago

abdonrd commented 5 years ago

Please, export "module" entry point in the package.json as ES Module Syntax (ESM).

More info about it here: https://www.pikapkg.com/about/

justinfagnani commented 3 years ago

I just this problem when trying to use Apollo. It wouldn't load because fast-json-stable-stringify isn't published as JS modules.

epoberezkin commented 3 years ago

I think it can be loaded either using esModuleInterop setting or with import stringify = require(“...”), same as most nodejs modules. I am probably missing something - why is it important to have default export in addition to it?

abdonrd commented 3 years ago

Because you can't use require / module.exports (CJS) directly in the browser. But you can use the standard import / export (ESM).

epoberezkin commented 3 years ago

Interesting... Wouldn’t it get bundled together anyway? Or you just load them as separate files?

abdonrd commented 3 years ago

Interesting... Wouldn’t it get bundled together anyway? Or you just load them as separate files?

During development I don't use any bundler.

Reference: https://modern-web.dev/guides/going-buildless/getting-started/

tirithen commented 3 years ago

Has there been any progress on getting this package ready for use as standard ESM module? I have projects that are still on a fork from this package, it would be great if it was possible to get the ESM version released as most recent projects will use ESM over CJS.

Thanks for an otherwise great package!

thescientist13 commented 3 years ago

@tirithen et all, There are a couple PRs open around advancing this forward

Keeping my eyes on those at the moment 👀 🤞

tirithen commented 1 year ago

@epoberezkin has there been any progress on getting the ESM export in place, I have a working fork of this at https://github.com/tirithen/fast-json-stable-stringify/blob/master/esm.js , but it really would be much better to get ESM support built into this repo as that is the one that is published as an npm package.

It has now been around 3 years since this issue was opened and I believe that the change is not that hard to make. CJS is okay for older projects but most new projects and frameworks need the standard ecmascript modules.

There is a good guide over at modern web on how to work with es modules https://modern-web.dev/guides/going-buildless/es-modules/ . There is also a more in depth guide over at Mozilla Developer Network https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules .

Fingers crossed that this can be resolved.

mateusrachid commented 1 year ago

Is anyone here maintaining a fork with ESM support? I believe many people would be interested.