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

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!

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (5 by maintainers)

Commits related to this issue

Most upvoted comments

I am using 0.13.2 and I still see this error.

Please re-open. Working with graphql on the client (with an RN project managed by expo) we don’t have NODE_ENV set, naturally, and getting this error when building the project, which causes the whole thing to crash. I don’t know what the source of the issue this check is for, but isn’t there something else you can check for, instead of NODE_ENV?

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?

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?

I don’t believe that setting NODE_ENV=production to be a viable long-term solution. Is there any thoughts on how to allow for different environments without this breaking?

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 .

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

@scniro It’s fixed in 0.13.0 and above.

@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

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.