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

Getting realm related error in console if using webpack.UglifyJsPlugin #1182

Closed
asci opened this issue Dec 26, 2017 · 16 comments
Closed

Getting realm related error in console if using webpack.UglifyJsPlugin #1182

asci opened this issue Dec 26, 2017 · 16 comments

Comments

@asci
Copy link

asci commented Dec 26, 2017

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!

@asci
Copy link
Author

asci commented Dec 26, 2017

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.

@asci
Copy link
Author

asci commented Dec 26, 2017

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?

@IvanGoncharov
Copy link
Member

@asci Didn't try this myself but #1174 should solve your problem. This fix is not released yet but you can test it with a local build.

@leebyron
Copy link
Contributor

leebyron commented Jan 8, 2018

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

@leebyron
Copy link
Contributor

leebyron commented Jan 8, 2018

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

@Fi1osof
Copy link

Fi1osof commented Jan 10, 2018

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

import {
DirectiveLocation,
type DirectiveLocationEnum,
} from '../language/directiveLocation';

I update my component MODX-Club/react-cms@80b111a#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

@scniro
Copy link

scniro commented Apr 5, 2018

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

@IvanGoncharov
Copy link
Member

@scniro It's fixed in 0.13.0 and above.

@gferreri
Copy link

I am using 0.13.2 and I still see this error.

@IvanGoncharov
Copy link
Member

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

@gferreri
Copy link

gferreri commented May 12, 2018 via email

@ciekawy
Copy link

ciekawy commented Oct 10, 2018

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?

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

@alondahari
Copy link

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?

@croossin
Copy link

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?

schuyler1d added a commit to StateVoicesNational/Spoke that referenced this issue Jul 13, 2021
@liviaalmeida
Copy link

@croossin I was able to get rid of this issue by removing devtool: 'source-map' in my webpack configuration

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

No branches or pull requests