-
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
Correct way to import apollo-server (rather than require) #1356
Comments
@meteorpublish Super odd,
|
+1 on this, also trying to use the flag with node 10. |
Any news about support on node 12 with --experimental-modules flag on? |
The correct syntax is this one: import {ApolloServer} from 'apollo-server'; // or apollo-server-[your framework] I was able to get this to work using https://github.com/standard-things/esm. Closing this issue now, please reopen if you have more questions! |
I was not - it complains that
Just saying. |
@rolfen what version of |
[email protected] This is how I am calling the code: After some tests, I realized that just changing the file extension from |
That's interesting that changing the extension would fix it. Normally, |
Using import apollo from 'apollo-server'
const { ApolloServer } = apollo Instead of what I assumed would work: import { ApolloServer } from 'apollo-server' Which throws the |
Would be nice to have proper ES Modules support (without @trevorblades should this issue be reopened? |
@dandv @djfarrelly it looks like we could support ES modules and CommonJS at the same time by following a pattern like the ones mentioned in the NodeJS API reference. That being said, Apollo Server is written in TypeScript and compiled to be compatible with CommonJS. We're passing the
If there was a way to replicate the pattern identified in the NodeJS reference above using TypeScript config options, that would be ideal. |
Still getting an error when using Node v14.4.0 |
I tried to import ApolloServer using Es6 syntax and the above was the error output. something isn't right with that still. |
I've managed to solve this exact problem (named ESM imports from the TypeScript output) in a package I'm maintaining, including the error message reported by @boblitex, by using conditional exports. These launched in Node 13.7.0, and have been no longer experimental since v13.10. You can see a diff implementing this for that package I'm maintaining. What needs to be done, essentially, is to output "exports": {
"node": {
"import": "./index.mjs",
"require": "./index.js"
},
"default": "./index.mjs"
}, |
Shouldn't we keep this issue open for tracking since the problem still persists? |
@trevorblades This issue still persists with the |
@mushketyk I'm doing |
Let's keep this issue closed because it's a duplicate of #3786. @trevorblades cool to hear it's working for you, though that's surprising. Should we close #3786? |
I'm trying to import 'apollo-server' using
--experimental-modules
in Node 10. What is the correct syntax?The text was updated successfully, but these errors were encountered: