graphql-js: "one instance of graphql" error when using esm package.
When using esm package (https://github.com/standard-things/esm) even most simple package.json configurations (only dependancies are esm and graphql-yoga) results in the Error: Cannot use GraphQLSchema "[object Object]" from another module or realm. error when using imports.
node -r esm testWithImport.js will fail while node testWithRequire.js and node -r esm testWithRequire.js will work.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (5 by maintainers)
This happens if you were to add a new npm script called
and a test file
serverWithImport.mjs:too.
The issue is that
graphql-yogais CJS (and loads the CJS entry ofgraphql) but you’re loading the ESM version ofgraphql.Because
graphglis running two entry points they create 2 separate instances (a limitation of their current dual approach). The way around it is forgraphqlto instantiate their instances in CJS and export them for the ESM entry to consume.