graphql / graphql-js

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

Cannot use ESM together with CJS -> cannot use "import" with graphql-express #2740

Open schrotie opened 4 years ago

schrotie commented 4 years ago

When mixing ECMA script modules (via import) and CommonJS modules in node.js (V14.5.0) then GraphQL complains that duplicate GraphQL modules cannot be used together.

One consequence of this is that it is to my knowledge impossible to use express-graphql together with import syntax. That is seemingly because "import" pulls other code than the "require" that express-graphql will use.

isabelleingato commented 3 years ago

Hello! New here and I'd like to look into this if that's okay. Do you happen to have a min repro example? I haven't seemed to run into this issue myself using express-graphql v0.12.0 with import syntax and requiring graphql v15.4.0 as cjs in the same project, so I want to make sure I'm understanding the question / set up.

I've seen similar errors before when mixing versions of graphql, unsure if related. https://github.com/graphql/graphql-js/blob/c589c3d285cb1ec44b09bf0b50ec041ec083760c/src/jsutils/instanceOf.ts#L22, https://github.com/graphql/graphql-js/issues/491

thanks!

schrotie commented 3 years ago

Sorry, I don't have a min-setup and I haven't worked with graphql for quite some time now.