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

Terser also causes #1182, Cannot use e "__Schema" from another module or realm #2523

Closed
benallfree opened this issue Apr 25, 2020 · 15 comments
Closed
Labels

Comments

@benallfree
Copy link

In reference to #1182, it seems that this is not fixed with Terser. I just ran into the problem again today.

Has anyone else been working on or experiencing this?

@frederikhors
Copy link

Working with Sapper and "graphql": "15.0.0" today and here we are!

Temporarily fixed by building with NODE_ENV=production. But something is broken I think. 🤕

@frederikhors
Copy link

This is an answer: https://stackoverflow.com/a/59289399/10088259.

Can we find and fix this process.env check in code?

@benallfree
Copy link
Author

I "fixed" it with the following patch-package:

graphql+14.6.0.patch

diff --git a/node_modules/graphql/jsutils/instanceOf.js b/node_modules/graphql/jsutils/instanceOf.js
index 8631fd1..6eddbc3 100644
--- a/node_modules/graphql/jsutils/instanceOf.js
+++ b/node_modules/graphql/jsutils/instanceOf.js
@@ -25,6 +25,8 @@ function instanceOf(value, constructor) {
     var className = constructor.name;
 
     if (className && valueClass && valueClass.name === className) {
+      console.warn('Graphql #1182 warning');
+      return true;
       throw new Error("Cannot use ".concat(className, " \"").concat(value, "\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results."));
     }
   }
diff --git a/node_modules/graphql/jsutils/instanceOf.js.flow b/node_modules/graphql/jsutils/instanceOf.js.flow
index 967969a..dfdb390 100644
--- a/node_modules/graphql/jsutils/instanceOf.js.flow
+++ b/node_modules/graphql/jsutils/instanceOf.js.flow
@@ -25,6 +25,8 @@ export default process.env.NODE_ENV === 'production'
         const valueClass = value.constructor;
         const className = constructor.name;
         if (className && valueClass && valueClass.name === className) {
+          console.warn('Graphql #1182 warning')
+          return true
           throw new Error(
             `Cannot use ${className} "${value}" from another module or realm.
 
diff --git a/node_modules/graphql/jsutils/instanceOf.mjs b/node_modules/graphql/jsutils/instanceOf.mjs
index eeea88d..dd11457 100644
--- a/node_modules/graphql/jsutils/instanceOf.mjs
+++ b/node_modules/graphql/jsutils/instanceOf.mjs
@@ -18,6 +18,8 @@ function instanceOf(value, constructor) {
     var className = constructor.name;
 
     if (className && valueClass && valueClass.name === className) {
+      console.warn('Graphql #1182 warning');
+      return true;
       throw new Error("Cannot use ".concat(className, " \"").concat(value, "\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results."));
     }
   }

@frederikhors
Copy link

Do you think it's just a matter of errors?

Maybe there is something wrong with the compilation phase.

And I don't want anything useless or, worse, harmful to end up in the final bundle.

@IvanGoncharov
Copy link
Member

Please ensure you don't have duplicate graphql packages in your node_modules.

  1. Remove node_modules and do fresh npm install
  2. npm ls graphql should show only one instance of graphql package

@benallfree
Copy link
Author

@IvanGoncharov I think this should stay open, people are encountering it and I can confirm this still occurs when only one graphql package is present.

@frederikhors
Copy link

don't have duplicate graphql packages in your node_modules.
Remove node_modules and do fresh npm install

DONE
DONE

Still the problem.

Please re-open it.

@idevelop
Copy link

idevelop commented Jun 8, 2020

I was able to work around this by setting mangle: false in terserOptions.

@danielrearden
Copy link
Contributor

The only time this error is thrown is when an instance of a type, directive or schema isn't an instance of the class exported by the graphql-js module that's using the instance. Most commonly this happens when another library being used has a dependency on another version of GraphQL. This is why graphql-js is normally listed a peer dependency. If you do have multiple versions of the library, you can try using yarn and dependency resolution to force the use of a single version.

That said, there may be other ways to break your code and trigger the error -- for example, by creating a shallow clone of the instance in question. Disabling this check is generally a bad idea because it can potentially lead to unexpected behavior or even more cryptic error messages.

If you're still encountering this issue, and you're certain it's not a problem with your dependencies, then it's most likely either an issue with your code or another library you're using. If you put together a minimum working example of the issue in the form or a repo or code sandbox, I can try to help you isolate the code that's causing the issue. However, requests for debugging help should really be posted elsewhere, like SO, reddit or the official Slack channel.

@macrozone
Copy link

this error currently happens with @apollo/client 3.0.0 even if you don't use graphql directly in your project and even if you have only one version of graphql in your yarn.lock

@cztomsik
Copy link

cztomsik commented Mar 3, 2021

still happens, we have only one version of graphql

I'm still investigating but it seems to have something to do with code-splitting (so not really an issue of this package but something is probably causing it to misbehave)

and yes, if minify is disabled, it works fine

@ramiAbdou
Copy link

Still having this issue as well, despite that we only have one version of graphql as well.

Help needed!

@cztomsik
Copy link

cztomsik commented Mar 14, 2021

@ramiAbdou ok in our case it was because aws-amplify had its own graphql bundled inside, check all of your deps it might be similar issue (but the rest was true, it was issue only when minified)

@croossin
Copy link

Still seeing this issue as well on 15.5.0. On Apollo 3.1.5 as well. Only works when setting NODE_ENV=production which doesn't work since we need multiple environment files.

@tito300
Copy link

tito300 commented Sep 24, 2021

We had a very old graphql version. To avoid this issue temporarily we took the following steps

  • bundled the graphql package into a separate chunk with webpack using cacheGroups.
  • excluded the new qraphql bundle from TerserPlugin minification using the exclude option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants