question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support ES modules

See original GitHub issue
import { 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:closed
  • Created 4 years ago
  • Reactions:14
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
derekjwilliamscommented, Mar 28, 2020

The workaround that I found (from https://github.com/apollographql/apollo-server/issues/1356) is

import apollo from 'apollo-server'
const { ApolloServer } = apollo
3reactions
glassercommented, Aug 3, 2021

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.)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found