oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.44k stars 2.78k forks source link

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

Open davemaier opened 5 months ago

davemaier commented 5 months ago

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.

Jarred-Sumner commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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.