graphql / graphql-js

A reference implementation of GraphQL for JavaScript
http://graphql.org/graphql-js/
MIT License
20.04k stars 2.02k forks source link

fix(esm): added export mapping to package.json for proper cjs/esm entrypoints #4081

Open favna opened 4 months ago

favna commented 4 months ago

With the current code that doesn't define export mapping modern tooling such as vitest v1.6.0 tries to access the CJS version of GraphQL in my project (https://github.com/favware/graphql-pokemon) because it doesn't know where to find the ESM version. This subsequently causes the error:

Cannot use GraphQLNonNull "Ability!" from another module or realm.

Ensure that there is only one instance of "graphql" in the node_modules
directory. If different versions of "graphql" are the dependencies of other
relied on modules, use "resolutions" to ensure only one version is installed.

https://yarnpkg.com/en/docs/selective-version-resolutions

Duplicate "graphql" modules cannot be used at the same time since different
versions may have different capabilities and behavior. The data from one
version used in the function from another could produce confusing and
spurious results.

By following the modern system of defining package entrypoints through the exports mapping this problem is solved because now vitest will properly access the ESM variant for graphql.

linux-foundation-easycla[bot] commented 4 months ago

CLA Signed


The committers listed above are authorized under a signed CLA.

netlify[bot] commented 4 months ago

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
Latest commit e47fb5fb748a99cc407781b1d540ca01071154b9
Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/6638ea1be863740008e525e2
Deploy Preview https://deploy-preview-4081--compassionate-pike-271cb3.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

favna commented 3 months ago

@benjie What is the way GraphQL addresses community bug fix PRs? I see GraphQL 16.8.2 got merged with a single bug fix as well and to be frank I'd say this one is equally as important because it also addresses bundlers and shipping code on modern ESM stacks.

benjie commented 3 months ago

What is the way GraphQL addresses community bug fix PRs?

GraphQL is a community operated technology, so all bug fix PRs are community bug fix PRs. Contributors are encouraged to represent their fixes at a GraphQL.js WG where it can be discussed with other community members; you can add yourself to an agenda here: https://github.com/graphql/graphql-js-wg/tree/main/agendas/2024

If you can't make any meetings (for example, due to timezone concerns) then you can request someone to represent a topic for you - hopefully someone else agrees with the need for the feature and will then represent it on your behalf.

to be frank I'd say this one is equally as important

We agree that this is important; there's active research being conducted that relates to (and predates) your PR - please see https://github.com/graphql/graphql-js/issues/4074 for more details.

favna commented 2 months ago

I keep procrastinating preparing something and signing up but I do feel like I want to. The timezone should be fine just fine, I'm from The Netherlands so only 2 hours ahead of UTC.

benjie commented 2 months ago

We’d love to see you there! Unfortunately I can’t make either of the next two meetings but I plan to be there in September.