Skip to content

GraphQL "only one instance" error when using minified aws-amplify.min.js #820

@jrasky

Description

@jrasky

Do you want to request a feature or report a bug?

Report a bug

What is the current behavior?

When including the minified build of aws-amplify from a CDN such as unpkg, graphql fails to load correctly.

index.html:

<script crossorigin src="https://unpkg.com/[email protected]/dist/aws-amplify.min.js"></script>
instanceOf.js:15 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.
    at t.default (instanceOf.js:15)
    at s (definition.js:98)
    at o (definition.js:84)
    at L (definition.js:253)
    at U (definition.js:257)
    at new i (wrappers.js:79)
    at i (wrappers.js:81)
    at Object.<anonymous> (introspection.js:427)
    at t (bootstrap 92871efc72a617fdd30f:19)
    at Object.<anonymous> (validate.js:13)

In particular, this is because graphql requires process.env.NODE_ENV="production" for minified builds. See graphql/graphql-js#1182, graphql/graphql-js#1174. In particular, aws-amplify does not take the recommended step in https://webpack.js.org/guides/production/#specify-the-environment:

https://github.com/aws/aws-amplify/blob/2bee05e427bea0b166a7bc787b50a2b4da54f79d/packages/aws-amplify/webpack.config.js#L22-L31

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than AWS Amplify.

What is the expected behavior?

aws-amplify loads correctly, as it does when using the non-minified version.

Which versions of Amplify, and which browser / OS are affected by this issue? Did this work in previous versions?

Chrome and Windows 10, although presumably this affects all browsers/OSs

You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions