-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Support ES modules #3786
Comments
The workaround that I found (from #1356) is
|
…ound for apollo-server module issues
Using that suggested solution with Node v14.4.0 fails with the following implementation: const express = require('express')
import apollo from 'apollo-server'
const { ApolloServer ) = apollo
const typeDefs = require('./schema.js')
const resolvers = require('./resolvers')
const models = require('./models')
const server = new ApolloServer({
typeDefs,
resolvers,
// Pass models as context to Apollo Server to give us access
// to models from our resolvers.
context: { models }
})
const app = express()
server.applyMiddleware({ app })
app.listen({ port: 4000 }, () =>
console.log(`🚀Server ready at http://localhost:4000${server.graphqlPath}`)
) The following is the error:
And after correcting for that in the package.json, I get the following error on requiring
|
I'm going to declare this out of scope for AS3 for now. Hopefully when this is needed we can do it in a way that's backwards-compatible and doesn't require a major version bump. |
I've put together a small example showing that nodejs imports are working with AS3 in Node 14: https://codesandbox.io/s/suspicious-wave-9z3r8?file=/src/index.js Note that I've added |
Hmm. While we didn't actually do any particular work to make ESM work, I agree with @trevorblades that it does seem to work, at least with Node 14! The comments from @lorensr and @derekjwilliams predate Node 14. @platocrat 's comment first is about what happens when you lack This comment references an error message that this comment suggests is resolved in Node v14.13 (and v12.20). (I think this PR is the relevant one.) This comment from @jaibatrik and this comment from @mushketyk don't have enough information to reproduce. I'm going to assume that this issue is now fixed, as long as you're on Node v14.13 or v12.20! If anyone (esp @jaibatrik or @mushketyk) can demonstrate ESM imports not working with one of those versions of Node (perhaps start by forking @trevorblades 's sandbox above) then we can reopen it. (Separately, it might be nice to publish |
@glasser it's very relevant for a server project because whoever uses Serverless functions like we do will always bundle them and ESM gives the best tree-shaking due to improve module dependency analysis by bundlers. I'm not sure if this issue should be reopened or another created but it would be a big plus for the community if Apollo Server was shipped with ESM files as well. |
Sure, we can make a new issue, but it would be great if that issue came with a clear example of something that doesn't work today. (This issue was about |
does not work in Node 13 with
"type": "module"
inpackage.json
. More info here: #1356 (comment)The text was updated successfully, but these errors were encountered: