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?
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. 馃
This is an answer: https://stackoverflow.com/a/59289399/10088259.
Can we find and fix this process.env check in code?
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."));
}
}
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.
Please ensure you don't have duplicate graphql packages in your node_modules.
node_modules and do fresh npm installnpm ls graphql should show only one instance of graphql package@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.
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.
I was able to work around this by setting mangle: false in terserOptions.
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.
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
Most helpful comment
DONE
DONE
Still the problem.
Please re-open it.