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
- Pin to GraphQL v0.11 due to graphql/graphql-js#1182 — committed to graphile/crystal by benjie 6 years ago
- Downgrade GraphQL to v0.11 due to graphql/graphql-js#1182 — committed to graphile/crystal by benjie 6 years ago
- works around issue https://github.com/graphql/graphql-js/issues/1182 — committed to claasahl/forex-sandbox by claasahl 6 years ago
- cypress test issue: trying to fix error of conflicting graphql versions. using workaround described here: https://github.com/graphql/graphql-js/issues/1182#issuecomment-388563851 NODE_ENV=production — committed to StateVoicesNational/Spoke by schuyler1d 3 years ago
I am using
0.13.2and 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_ENVset, 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 ofNODE_ENV?I wonder how the
NODE_ENVis 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
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 ofgraphql, like forreactorreact-dom?I don’t believe that setting
NODE_ENV=productionto 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
productionOn Sat, May 12, 2018, 5:16 AM Ivan Goncharov notifications@github.com wrote:
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.0and 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
GraphQLScalarTypeandGraphQLObjectTypeconstructors both geteas a shortcut during the minifying. And when graphql-js tries to compare them — condition istrueand it throws an error.