-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Provide a clear path on how to support graphql-js 16 and 17 at the same time as a esm and cjs library author #3603
Comments
see #3616 which could also be a workaround for the dual-package hazard with cjs/esm compatibility |
We shouldn't. Pure ESM is a good and necessary major change; it's ok for the ecosystem to upgrade to v17 when ready and leave v16 behind. See these comments for detailed reasons why pure ESM is good and attempting both ESM and CJS is not: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#gistcomment-3850849 I'm really looking forward to the pure ESM jaydenseric/graphql-upload#290 (review) If that takes too long I'll move it to pure ESM regardless. There is no need to overthink and over-engineer all this. CJS has overstayed its welcome and we’re collectively torturing ourselves with it for no particular reason; the time is now to switch to pure ESM. There is never going to be a better time. Many of Sindre Sorhus's packages are pure ESM, as are most of mine, packages like |
It took too long 😂 It would be a massive improvement though if import { GraphQLError, GraphQLScalarType } from "graphql"; This causes all the library to be loaded when we only need to import those two things. Ideally there would be a deep import to get only
|
As it seems right now graphql-js 17 will ship without a commonjs solution.
Since ESM modules can only be loaded with a dynamic import within a commonjs context that will make a lot of libraries that support multiple graphql-js versions (commonjs and ESM in GraphQL.js 16 and ESM only in GraphQL.js 17) AND both CommonJS and ESM a pain to use and maintain.
Before making the decision to only ship ESM, there should be a clear path for those libraries. Otherwise, the ecosystem around graphql-js will result in kind of a broken state.
There was no clear description provided of why graphql-js 17 will be ESM only in the PR: #3552
It would be great to hear the benefit and intention of dropping CommonJS support.
To me, it seems like the Node.js ESM ecosystem is not major enough to justify dropping CommonJS.
A common reason for going ESM only is the "dual package hazard" issue, where a module is loaded as both ESM and CJS in the same application resulting in subtle bugs e.g. when relying on
instanceof
checks.Instead could be another solution to add something like this to the "entry" modules to ensure only one version of GraphQL.js is loaded? Are there use-cases in which you would want to run two
graphql-js
versions alongside each other?However, this would still not solve the issue of an esm-only dependency requiring esm graphql and another cjs-only dependency requiring cjs graphql...
A possible workaround could be to instruct people to do ad-hoc esm graphql to cjs graphql conversions... I already tested this method...
scripts/cjsify-graphql.js
Related PR links:
instanceof
issue impacts graphql-js-wg#63The text was updated successfully, but these errors were encountered: