Graphql-js: Getting realm related error in console if using webpack.UglifyJsPlugin

Created on 26 Dec 2017  Â·  13Comments  Â·  Source: graphql/graphql-js

Hello,

I have a bit strange situation. If I build my project with UglifyJsPlugin I get this error:

Uncaught Error: Cannot use e "__Schema" 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.

I checked node_modules and I have only one graphql module installed and during development, I don't have this error. Moreover, my app still works fine and makes requests.

When I debug instanceOf I see something like this:

arguments[1].toString();
"function e(t){r(this,e),this.name=t.name,this.description=t.description,this.astNode=t.astNode,this._scalarConfig=t,"string"!=typeof t.name&&Object(Y.a)(0,"Must provide name."),"function"!=typeof t.serialize&&Object(Y.a)(0,this.name+' must provide "serialize" function. If this custom Scalar is also used as an input type, ensure "parseValue" and "parseLiteral" functions are also provided.'),(t.parseValue||t.parseLiteral)&&("function"!=typeof t.parseValue||"function"!=typeof t.parseLiteral)&&Object(Y.a)(0,this.name+' must provide both "parseValue" and "parseLiteral" functions.')}"
arguments[0].constructor.toString()
"function e(t){r(this,e),this.name=t.name,this.description=t.description,this.astNode=t.astNode,this.extensionASTNodes=t.extensionASTNodes,this.isTypeOf=t.isTypeOf,this._typeConfig=t,"string"!=typeof t.name&&Object(Y.a)(0,"Must provide name."),t.isTypeOf&&"function"!=typeof t.isTypeOf&&Object(Y.a)(0,this.name+' must provide "isTypeOf" as a function.')}"

Any ideas what it could be and how to avoid it?

Versions:

    "graphql": "^0.12.3",
    "webpack": "^3.8.1",
    "webpack-dev-server": "^2.9.4",

Thanks, and btw, Happy New Year!

Most helpful comment

I am using 0.13.2 and I still see this error.

All 13 comments

So, as far as I can see the problem is that GraphQLScalarType and GraphQLObjectType constructors both get e as a shortcut during the minifying. And when graphql-js tries to compare them — condition is true and it throws an error.

So, I found how to avoid the issue:
use

mangle: false

option for UglifyJsPlugin, but the problem is that get additional 37Kb (124Kb -> 161Kb) on output bundle size for vendors. Any ideas? Maybe there is a production version of graphql, like for react or react-dom?

@asci Didn't try this myself but https://github.com/graphql/graphql-js/pull/1174 should solve your problem. This fix is not released yet but you can test it with a local build.

Really sorry about this issue! I'm glad you were able to find a temporary work around, and I'm working on getting a new release out shortly that disables the check in mangled production bundles

Thanks for sharing your diagnosis and debugging details. I found a similar conclusion which led to #1174. I'm going to close this issue since we have a fix that is release-ready

Good day!
@leebyron, is this fixed? I got this error on production from verrsion 0.12+. Before upgrade all works fine. Reason for upgrade: moved DirectiveLocation into ../language/directiveLocation https://github.com/graphql/graphql-js/blob/740b7fae02368b1ea24f9e12a62502c49cd9fb95/src/type/directives.js#L19-L22

I update my component https://github.com/MODX-Club/react-cms/commit/80b111aecf7669c9785e5b1614d07cce07c98289#diff-1d00843fa6d5ebeccc3a828d9b30afea
import { DirectiveLocation, from 'graphql/language/directiveLocation';
Is this may be wrong inclution?

All project dependencies (but in node_modules only one graphql module) https://github.com/MODX-Club/ShopModxBox/blob/master/assets/components/modxsite/templates/shopmodx/v4.0/package-lock.json

Closed? Getting the same error on 0.11.11

Uncaught Error: Cannot use e "__Schema" 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

@scniro It's fixed in 0.13.0 and above.

I am using 0.13.2 and I still see this error.

I am using 0.13.2 and I still see this error.

@gferreri Did you specify production enviroment to your bundler, here is how to do it for webpack:
https://webpack.js.org/guides/production/#specify-the-environment

That was indeed my problem. NODE_ENV was not set to production

On Sat, May 12, 2018, 5:16 AM Ivan Goncharov notifications@github.com
wrote:

I am using 0.13.2 and I still see this error.

@gferreri https://github.com/gferreri Did you specify production
enviroment to your bundler, here is how to do it for webpack:
https://webpack.js.org/guides/production/#specify-the-environment

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/graphql/graphql-js/issues/1182#issuecomment-388542102,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACDyBr1REA1crjVRIaa4t2_IJ5HKcw0Tks5txqh9gaJpZM4RM-4j
.

I wonder how the NODE_ENV is supposed to exist in mobile device i.e. for Ionic or React Native build where content is not serverd by any http server but is opened directly from a filesystem? shouldn't the ticket be reopened?

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. 🤕

Was this page helpful?
0 / 5 - 0 ratings