type-graphql: Cannot use GraphQLSchema from another module or realm
Describe the bug I installed express-graphql and typed-graphql, then I defined my entities and built the schema, when I pass the Schema to express-graphql and added it to my express app. As soon as I open grahpiql in my browser and run a query I get the error:
{
"errors": [
{
"message": "Cannot use GraphQLSchema \"[object Object]\" from another module or realm.\n\nEnsure that there is only one instance of \"graphql\" in the node_modules\ndirectory. If different versions of \"graphql\" are the dependencies of other\nrelied on modules, use \"resolutions\" to ensure only one version is installed.\n\nhttps://yarnpkg.com/en/docs/selective-version-resolutions\n\nDuplicate \"graphql\" modules cannot be used at the same time since different\nversions may have different capabilities and behavior. The data from one\nversion used in the function from another could produce confusing and\nspurious results."
}
]
}
Enviorment (please complete the following information):
- OS: Ubuntu 18.04
- Node 10.9.0
- Package version 0.13.1
- TypeScript version 3.0.1
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 29 (14 by maintainers)
Commits related to this issue
- had to delete lock files and node_modules https://github.com/19majkel94/type-graphql/issues/144#issuecomment-418195929 — committed to nouex/rose-golden by nouex 5 years ago
I got it to work, by explicitly specifying the same version in my package.json as needed by type-graphql. I also had to delete my node_modules and package-lock.json to make npm dedupe the graphql dependency.
But I guess it would be better if type-graphql would specify graphql as peerDependency, to prevent such problems.
To make it a bit clear for newcomers that are looking for a solution in this issue - there’s a little guide in FAQ for this problem: https://19majkel94.github.io/type-graphql/docs/faq.html#i-got-error-like-cannot-use-graphqlschema-object-object-from-another-module-or-realm-how-to-fix-that
I switched from
npm
toyarn
(deleting ‘node_modules’ and ‘package-lock.json’ and ‘rebuilding’) and then added this to ‘package.json’:It’s all working again! 😌
@manavm1990 https://typegraphql.com/docs/faq.html#how-do-i-fix-this-error-cannot-use-graphqlschema-object-object-from-another-module-or-realm
I got it to work by removing
node_modules/type-graphql/node_modules/graphql
, but this isn’t really feasible in a production environment. Helps unblock local development until all maintainers get onboard with GQL 14package.json
So don’t. Just specify the versions you know are compatible at the time of writing. Everyone does it like this. If a new version comes and it is compatible, you can add it later.
I think you need to use it always-even apollo-server-core expects it at as peer dep.
running an apollo server without
graphql
installed. To make it easier just put it in the readme.md. Everyone does it like that. Will open a PR.