Closed peebles closed 3 years ago
Hm thanks - I’ll have a look
My "fix" for this in in main.js:
const { graphqlHTTP } = require('express-graphql');
and
app.use( "/graphql", graphqlHTTP({ schema: executableSchema, graphiql: true, rootValue: root }) );
Cool - I'll have a look at this soon. Thanks for raising this.
Hey so this one is interesting. It looks like you're using Node's native esm, which is causing the failure. My code assumes you're using the esm
package off of npm (which will work). What's interesting is that none of my generated code here will work with Node's native esm - it all assumes you're using the esm package.
If you can't / don't want to use the esm package off of npm, then using require for express-graphql here would absolutely be the correct fix, but like I said you'll have a lot of trouble getting all the generated graphql code to work.
I'll look at making this clearer in the docs.
I am a "require" kind of old-timer. I am using node 12.12. I believe I am using the esm
package:
$ ls node_modules/esm/
LICENSE README.md esm esm.js index.js node_modules package.json
and
$ cat index.js
require = require("esm")(module/* , options */)
module.exports = require("./main.js")
and:
$ node main.js
/Users/peebles/zhortech/zql/main.js:1
import { MongoClient } from "mongodb";
^^^^^^
SyntaxError: Cannot use import statement outside a module
@peebles in your example above, I believe you want
$ node index.js
Using your simple example of a server, which includes a line that looks like
Throws an error. You can see this using the repl: