Skip to content
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

Duplicate "graphql" modules error running a single-file executable built with bun build when using yoga or apollo #11785

Open
davemaier opened this issue Jun 11, 2024 · 4 comments
Labels
bug Something isn't working bundler Something to do with the bundler minifier

Comments

@davemaier
Copy link

What version of Bun is running?

1.1.12

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

  1. Clone https://github.com/davemaier/bun-graphql-sample-server-yoga
  2. bun install
  3. bun build ./server.ts --compile --outfile server
  4. ./server

What is the expected behavior?

The server should start, just like if it was started with bun run

What do you see instead?

./server
47766 |     var _value$constructor;
47767 |     const className = constructor.prototype[Symbol.toStringTag];
47768 |     const valueClassName = Symbol.toStringTag in value ? value[Symbol.toStringTag] : (_value$constructor = value.constructor) === null || _value$constructor === undefined ? undefined : _value$constructor.name;
47769 |     if (className === valueClassName) {
47770 |       const stringifiedValue = inspect(value);
47771 |       throw new Error(`Cannot use ${className} "${stringifiedValue}" 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.`);

error: Cannot use GraphQLSchema "{ __validationErrors: [], description: undefined, extensions: {}, astNode: undefined, extensionASTNodes: [], _queryType: Query, _mutationType: undefined, _subscriptionType: undefined, _directives: [@include, @skip, @deprecated, @specifiedBy], _typeMap: { Query: Query, String: String, Boolean: Boolean, __Schema: __Schema, __Type: __Type, __TypeKind: __TypeKind, __Field: __Field, __InputValue: __InputValue, __EnumValue: __EnumValue, __Directive: __Directive, __DirectiveLocation: __DirectiveLocation }, _subTypeMap: {}, _implementationsMap: {} }" 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.
      at instanceOf3 (/$bunfs/root/server:47771:13)
      at useSchema (/$bunfs/root/server:54237:7)
      at new YogaServer (/$bunfs/root/server:59831:28)
      at createYoga (/$bunfs/root/server:59763:19)
      at /$bunfs/root/server:60056:12

Additional information

This could be related to #3659 where a similar error came up. I've tried the reproduction repo from the referenced issue and with the setup in the repo everything works fine when using bun build. The trouble starts when I try to use graphql-yoga.
I've also tried with @apollo/server -> doesn't work, same error.

@davemaier davemaier added bug Something isn't working needs triage labels Jun 11, 2024
@Jarred-Sumner
Copy link
Collaborator

is this using a code generator for graphql schemas? i wonder if it's embedding a filesystem path somewhere

if you do BUN_JSC_dumpModuleLoadingState=1 does that report anything interesting like loading a node_modules/graphql*?

@davemaier
Copy link
Author

The graphql schema is directly created using graphql.createSchema and I don't think that there is any code generation involved. Compared to this repo where everything works fine, I only added graphql-yoga.

Setting BUN_JSC_dumpModuleLoadingState=1 does not change the output of bun build or from running the built binary for me.

@StefanFeederle
Copy link

I think I have a similar issue. Types that I import from "graphql" are not the same instances that "graphql-compose" imports internally from "graphql". Bun 1.1.13 on windows 11

@wcastand
Copy link

wcastand commented Jun 24, 2024

same issue with gql.tada
trying to run the gql.tada check result in an error saying there is multiple instances of graphql (even after adding overrides or resolutions to a single graphql version.

EDIT: i looked into it with someone working on gql.tada and it seems that one of the deps use a graphql version that is too old and the override doesn't fix it.

deps is expo-dev-menu is that can help.

@paperdave paperdave added minifier bundler Something to do with the bundler and removed needs triage labels Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bundler Something to do with the bundler minifier
Projects
None yet
Development

No branches or pull requests

5 participants