Support ES modules
See original GitHub issueimport { ApolloServer } from 'apollo-server'
does not work in Node 13 with "type": "module"
in package.json
. More info here: https://github.com/apollographql/apollo-server/issues/1356#issuecomment-567101161
import { ApolloServer } from 'apollo-server'
^^^^^^^^^^^^
SyntaxError: The requested module 'apollo-server' does not provide an export named 'ApolloServer'
at ModuleJob._instantiate (internal/modules/esm/module_job.js:92:21)
at async ModuleJob.run (internal/modules/esm/module_job.js:107:20)
at async Loader.import (internal/modules/esm/loader.js:164:24)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:14
- Comments:7 (5 by maintainers)
Top Results From Across the Web
JavaScript modules via script tag | Can I use... Support tables ...
Loading JavaScript module scripts (aka ES6 modules) using <script type="module"> Includes support for the nomodule attribute. Usage % of. all users, all tracked ......
Read more >JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >ECMAScript modules | Node.js v19.3.0 Documentation
Node.js fully supports ECMAScript modules as they are currently specified and provides interoperability between them and its original module format, CommonJS.
Read more >ES modules in service workers - web.dev
Service workers can use static imports of ES modules to bring in extra code, as an alternative to importScripts().
Read more >ES Modules | Dev Cheatsheets - Michael Currin
As of ES6 (ES2015), JavaScript supports a native module format called ES Modules, or ECMAScript Modules. This is modern way to do modules...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The workaround that I found (from https://github.com/apollographql/apollo-server/issues/1356) is
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
"type": "module"
, and then is about a require in their own code, not in Apollo Server.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
apollo-server
built as ESM itself, but I don’t know if that actually helps with any specific use cases. For Apollo Client we’re doing that so you can load directly from a site like esm.run, but that seems less relevant for a server project.)