I develop a package that uses graphql. It has peerDeps:
"peerDependencies": {
"@types/graphql": "~0.10.4 || ~0.11.0 || ~0.12.0 || ~0.13.0",
"graphql": "~0.10.4 || ~0.11.0 || ~0.12.0 || ~0.13.0"
}
Using standart package development flow, I make a repo of this package, link it with yarn link, then go to test project and add it via yarn link package/name.
And on printSchema in the package I get:
Error: Cannot use GraphQLObjectType "__Directive" 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.
resolutions in both packages don't work.
And I see no options to suppress this behavior.
I think that there should be such option, to suppress this check on such cases (maybe via env variable or something else), in other case I don't understand, how to develop and check packages locally
Ah, sorry, found pull request and understood, that this can be suppressed by seting node env to production
@terion-name Note: that by disabling this check you don't solve the underlying problem there is very high chance that graphql-js will start to behave unpredictably.
@IvanGoncharov yes, it didn't solve the problem :(
Now getting Error: Unknown type: __Directive. and nothing works.
Any ideas how to handle this?
@terion-name Can you please run npm ls graphql and post the output here?
You almost certainly have multiple instances of the GraphQL.js module being pulled in and interacting with each other. This can happen when you attempt to use multiple different versions.
Yarn's "resolutions" key in package.json is a good way to enforce a specific version for an entire installation, which can help you solve this problem
@leebyron resolutions doesn't work. because, as I've written, I am linking a package that is in develop to project it is developed for via yarn link. So they, are in different places and have different node_modules
@IvanGoncharov in project:
โโโฌ [email protected]
โ โโโฌ [email protected]
โ โ โโโ UNMET DEPENDENCY [email protected]
โ โโโ UNMET DEPENDENCY [email protected]
โโโฌ [email protected]
โ โโโ [email protected]
โโโฌ [email protected]
โโโฌ [email protected]
โโโ [email protected] deduped
in package (that is linked and which code causes error):
โโโฌ [email protected]
โ โโโฌ [email protected]
โ โ โโโ UNMET DEPENDENCY [email protected]
โ โโโ UNMET DEPENDENCY [email protected]
โโโฌ [email protected]
โโโ [email protected]
So they, are in different places and have different node_modules
@terion-name I see. I can't think of any good solution to this problem that we could implement inside graphql-js ๐
Possible workaround: copy node_modules/graphql somewhere and run yarn link in it and also link it in two projects you mentioned.
@IvanGoncharov ok, I've found a workaround: remove node_modules in developing package and add it to test project with yarn add file:...
This has drawbacks, like problems with build of package and need to re-add on each change, but this is better than nothing
Most helpful comment
@terion-name I see. I can't think of any good solution to this problem that we could implement inside
graphql-js๐Possible workaround: copy
node_modules/graphqlsomewhere and runyarn linkin it and also link it in two projects you mentioned.