-
Notifications
You must be signed in to change notification settings - Fork 61
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
Can't import from graphql-type-json #277
Comments
Yeah, my build is wrong – I didn't properly tag the ES modules to be usable by Node. Do you want to send in a PR to fix the |
OK, will do. |
1 similar comment
OK, will do. |
OK, this is all way messier than I thought. I am trying to do this using "pure" node, so not the esm module. First, the fix for your code seems to be the following.
this will redirect import and require to the appropriate files. Note that I have renamed es/index.js
in es/index.mjs throws an error as well, because graphql itself does not provide proper entry points for their import/export stuff either. This goes to the relevant graphql files and subdirectories directly and works:
This, however is in direct contradiction to the sample code they list on https://www.npmjs.com/package/graphql. There, they do an
which does not work. I just verified that yesterday. I am not sure this is the right time yet to apply a fix to your code before the graphql people have not fixed theirs. What do you think? Here are my workarounds for the project I am working on: use imports from graphql like this
until further notice. For your module I use a little two liner local ES6 module that imports the top level export object from your module and then exports the two definitions for GraphQLJSON and GraphQLJSONObject. |
OK, I am giving up on import/export from graphql and graphql-type-json and will revert back to require. This is simply not ready for prime time. I was testing the workaround mentioned above and that leads to the following infamous error:
Apparently, two instances of the graphql import are generated. I'll check back in a year or so, this looks like it will take some time. Shame about the ES6 modules, working with import/export leads to cleaner code and the circular references possible enable better modularization. |
OK, I have reported the
to the graphQL developers. If they fix the issue, maybe we can also fix this one. |
Ahh, okay, thanks for digging into things. Sorry this didn't quite work. Let me know if there's any progress on the upstream end. I guess I should probably remove the ES module exports here, as they don't really help anyone and at best just lead to confusion. |
Maybe wait a couple of days before removing, I got a really fast reaction from one of the graphql developers. I have sent him a minimal example to reproduce the problem and hopefully there will be a reply soon. |
any news? |
Hi,
this is a minimal code snippet from a module I am developing:
import { GraphQLJSONObject } from 'graphql-type-json';
It lives inside a xxx.mjs file, which is imported by other ES6 modules in the application.
When I run this (node version 13.14) I get a fatal error:
import { GraphQLJSONObject } from 'graphql-type-json'; ^^^^^^^^^^^^^^^^^ SyntaxError: The requested module 'graphql-type-json' does not provide an export named 'GraphQLJSONObject'
I looked at the package.json file in your module and I am not sure it does the right thing, according to the node.js documentation:
"module": "es/index.js",
This is ignored by node, according to their docs (https://nodejs.org/docs/latest-v13.x/api/esm.html). Instead, one is supposed to use a conditional export in package.json , like this:
"exports": { "import": "./main-module.js", "require": "./main-require.cjs" },
main-module.js does the ES6 thing and main-require.cjs the commonJS one. Any thoughts?
The text was updated successfully, but these errors were encountered: