-
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
"one instance of graphql" error when using esm package. #1479
Comments
@Pokute Can you please setup sample repo to reproduce this issue? |
@Pokute Can you also run |
Repo for reproducing: https://github.com/Pokute/graphql-esm-bug |
@jdalton Do you have opinions on this? |
This happens if you were to add a new npm script called
and a test file import graphglYoga from 'graphql-yoga';
import { GraphQLObjectType, GraphQLSchema, GraphQLString } from "graphql";
const { GraphQLServer } = graphglYoga
var Something = new GraphQLObjectType({
fields: {
else: { type: GraphQLString },
},
name: 'Something',
})
var schema = new GraphQLSchema({
query: new GraphQLObjectType({
fields: {
something: {
type: Something,
},
},
name: 'Query',
}),
});
var server = new GraphQLServer({ schema });
const instance = server.start(); // defaults to port 4000 too. The issue is that Because |
@jdalton Thanks for detail response. I have a few questions about the proposed solution:
Is it something like this? const {
GraphQLObjectType,
// ....
} = require('./graphql');
export GraphQLObjectType;
// ... If so, it makes tree shaking impossible, right? |
No. That wouldn't work in import GraphQLObjectType from "./types/object.js" The other option is to drop |
@jdalton Thanks for example.
We can't split every type into a separate file since it will create a bunch of circular dependencies and also affect code readability.
AFAIK, IE doesn't support IMHO, Having two instances of the same library is a problem by itself even if it doesn't trigger any errors. So even if we drop See Lee's comment here: #996 (comment)
Moreover I would argue that this problem is not a something specific to this particular library since a lot of other libraries also use classes, singletons, etc. @Pokute For now, I think the most practical solution would be to open a feature request against |
core-js has a shim for it. You could also use any-other property to detect the instance
This is not an
FWIW I'm a Node core member and a member of the Node Module Working Group. Our recommendation is to not adopt Update: As of |
Just removing the .mjs entry point might be a good interim solution. Is anyone even using .mjs in production? Plenty of people are using esm, and this is causing hard-to-track bugs. |
@jdalton thank you for v3.0.83! |
@jdalton Thanks for fixing it in ESM. |
Just a heads up this doesn't fix Update: Related #1536. |
I am, and several popular published packages depend on it.
That's bad news, people rely on the propper Node.js resolution order. This issue is being over complicated. |
It's not so bad when the alternative is non-working code. For
👋 Node core and Node Module WG member here. There is no set date for when Adopting The |
My solution was to replace import graphql from 'graphql' with import graphql from 'graphql/index.js' I was using flags |
When using
esm
package (https://github.com/standard-things/esm) even most simple package.json configurations (only dependancies areesm
andgraphql-yoga
) results in theError: Cannot use GraphQLSchema "[object Object]" from another module or realm.
error when using imports.node -r esm testWithImport.js
will fail whilenode testWithRequire.js
andnode -r esm testWithRequire.js
will work.The text was updated successfully, but these errors were encountered: