Skip to content
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

ESM TypeError: resolvable is not a function #7895

Closed
macrozone opened this issue Jul 4, 2024 · 8 comments
Closed

ESM TypeError: resolvable is not a function #7895

macrozone opened this issue Jul 4, 2024 · 8 comments

Comments

@macrozone
Copy link

Issue Description

when switching to ESM, apollo server no longer starts. you get this error:

TypeError: resolvable is not a function
    at ApolloServer._start (/path/to/project/node_modules/@apollo/server/dist/esm/ApolloServer.js:127:25)
    at ApolloServer.start (/path/to/project/node_modules/@apollo/server/dist/esm/ApolloServer.js:115:27)

Link to Reproduction

not yet

Reproduction Steps

  1. install "@apollo/server": "^4.10.4",
  2. set "type": "module" in package.json
  3. start apollo server

import { ApolloServer } from "@apollo/server";

 const server = new ApolloServer<{}>({
    schema,
    plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],
  });

 await server.start();

@macrozone
Copy link
Author

macrozone commented Jul 4, 2024

looks like a "left-pad" situation. https://github.com/josephg/resolvable is a 17 liner and has not been updated in 3 years.

come on, just don't use dependencies like that

@ivosabev
Copy link

ivosabev commented Jul 4, 2024

I use the following patch-package patch

diff --git a/node_modules/@apollo/server/dist/esm/ApolloServer.js b/node_modules/@apollo/server/dist/esm/ApolloServer.js
index b716f63..25370aa 100644
--- a/node_modules/@apollo/server/dist/esm/ApolloServer.js
+++ b/node_modules/@apollo/server/dist/esm/ApolloServer.js
@@ -1,7 +1,7 @@
 import { isNodeLike } from '@apollo/utils.isnodelike';
 import { InMemoryLRUCache, PrefixingKeyValueCache, } from '@apollo/utils.keyvaluecache';
 import { makeExecutableSchema } from '@graphql-tools/schema';
-import resolvable from '@josephg/resolvable';
+import resolvable from '@josephg/resolvable/index.js';
 import { GraphQLError, assertValidSchema, print, printSchema, } from 'graphql';
 import loglevel from 'loglevel';
 import Negotiator from 'negotiator';

@macrozone
Copy link
Author

I use the following patch-package patch

diff --git a/node_modules/@apollo/server/dist/esm/ApolloServer.js b/node_modules/@apollo/server/dist/esm/ApolloServer.js
index b716f63..25370aa 100644
--- a/node_modules/@apollo/server/dist/esm/ApolloServer.js
+++ b/node_modules/@apollo/server/dist/esm/ApolloServer.js
@@ -1,7 +1,7 @@
 import { isNodeLike } from '@apollo/utils.isnodelike';
 import { InMemoryLRUCache, PrefixingKeyValueCache, } from '@apollo/utils.keyvaluecache';
 import { makeExecutableSchema } from '@graphql-tools/schema';
-import resolvable from '@josephg/resolvable';
+import resolvable from '@josephg/resolvable/index.js';
 import { GraphQLError, assertValidSchema, print, printSchema, } from 'graphql';
 import loglevel from 'loglevel';
 import Negotiator from 'negotiator';

thank you, this indeed fixes the issue.

its weird that this happens though, shouldn't node respect the main field as fallback?

@pthieu
Copy link

pthieu commented Jul 6, 2024

fails on node 20 and above, works on 18
i didn't test any other versions

@trevor-scheer
Copy link
Member

trevor-scheer commented Jul 11, 2024

I haven't spent much time trying to understand the issue, the JS file appears to be ESM compatible. Maybe the package.json from the resolvable dependency needs a module field? In any case, I opened a PR to inline the dependency which should resolve it. Could someone with a reproduction handy please test it out? There are builds on the PR you can install via the Codesandbox CI comment. Thanks for reporting!

@macrozone
Copy link
Author

@trevor-scheer I can confirm that your MR works

trevor-scheer added a commit that referenced this issue Jul 22, 2024
Issue #7895
reports that AS4 fails to build for ESM due to the resolvable
dependency.

I'm actually unsure _why_ this is happening though, since the shipped JS
appears to be ESM compatible:
https://unpkg.com/@josephg/resolvable@1.0.1/index.js

@macrozone would you mind testing the builds from this PR (see
Codesandbox CI comment) and letting me know if this resolves the issue
in your project?
@trevor-scheer
Copy link
Member

Fixed via #7900, should be available in @apollo/server@4.10.5 momentarily. Thanks for reporting!

Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants