@apollo/server (v4) Lots of typescript compilation errors

I’m trying to migrate our GraphQL node server from apollo-server-express (v3) to the new @apollo/server (v4), but I keep getting typescript compilation errors from inside node_modules @apollo/server/* when running tsc As in, not from my code…

I’ve tried everything I can think of to resolve this, but I am at a dead end. I’m using the recommended compilation settings in my tsconfig.json

Node version: v18.12.1
Typescript version: 4.6.2

Errors output from tsc: ❯ node -v v18.12.1 ❯ npx tsc node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:64:35 - error TS1139: Type parameter declaration expected.

64 export declare class ApolloServer {
~~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:64:42 - error TS1005: ‘;’ expected.

64 export declare class ApolloServer {
~~~~~~~~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:64:51 - error TS1128: Declaration or statement expected.

64 export declare class ApolloServer {
~~~~~~~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:65:22 - error TS1005: ‘,’ expected.

65 private internals;
~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:66:42 - error TS1005: ‘(’ expected.

66 readonly cache: KeyValueCache;
~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:67:28 - error TS1005: ‘,’ expected.

67 readonly logger: Logger;
~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:69:5 - error TS1005: ‘,’ expected.

69 start(): Promise;
~~~~~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:70:5 - error TS1005: ‘,’ expected.

70 startInBackgroundHandlingStartupErrorsByLoggingAndFailingAllRequests(): void;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:71:5 - error TS1005: ‘,’ expected.

71 private _start;
~~~~~~~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:71:19 - error TS1005: ‘,’ expected.

71 private _start;
~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:72:51 - error TS1005: ‘,’ expected.

72 private maybeRegisterTerminationSignalHandlers;
~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:73:27 - error TS1005: ‘,’ expected.

73 private _ensureStarted;
~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:75:5 - error TS1005: ‘,’ expected.

75 private logStartupError;
~~~~~~~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:75:28 - error TS1005: ‘,’ expected.

75 private logStartupError;
~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:76:35 - error TS1005: ‘,’ expected.

76 private static constructSchema;
~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:77:45 - error TS1005: ‘,’ expected.

77 private static generateSchemaDerivedData;
~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:79:5 - error TS1005: ‘,’ expected.

79 private addDefaultPlugins;
~~~~~~~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:79:30 - error TS1005: ‘,’ expected.

79 private addDefaultPlugins;
~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:81:5 - error TS1005: ‘,’ expected.

81 executeHTTPGraphQLRequest({ httpGraphQLRequest, context, }: {
~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:85:5 - error TS1005: ‘,’ expected.

85 private errorResponse;
~~~~~~~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:85:26 - error TS1005: ‘,’ expected.

85 private errorResponse;
~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:86:24 - error TS1005: ‘,’ expected.

86 private prefersHTML;
~

node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:90:5 - error TS1005: ‘,’ expected.

90 executeOperation<TData = Record<string, unknown>, TVariables extends VariableValues = VariableValues>(request: Omit<GraphQLRequest, ‘query’> & {
~~~~~~~~~~~~~~~~

node_modules/@apollo/server/dist/esm/externalTypes/plugins.d.ts:20:37 - error TS1139: Type parameter declaration expected.

20 export interface ApolloServerPlugin {
~~

node_modules/@apollo/server/dist/esm/externalTypes/plugins.d.ts:20:49 - error TS1005: ‘;’ expected.

20 export interface ApolloServerPlugin {
~~~~~~~

node_modules/@apollo/server/dist/esm/externalTypes/plugins.d.ts:22:5 - error TS1005: ‘,’ expected.

22 requestDidStart?(requestContext: GraphQLRequestContext): Promise<GraphQLRequestListener | void>;
~~~~~~~~~~~~~~~

node_modules/@apollo/server/dist/esm/externalTypes/plugins.d.ts:23:5 - error TS1005: ‘,’ expected.

23 unexpectedErrorProcessingRequest?({ requestContext, error, }: {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@apollo/server/dist/esm/externalTypes/plugins.d.ts:27:5 - error TS1005: ‘,’ expected.

27 contextCreationDidFail?({ error }: {
~~~~~~~~~~~~~~~~~~~~~~

node_modules/@apollo/server/dist/esm/externalTypes/plugins.d.ts:30:5 - error TS1005: ‘,’ expected.

30 invalidRequestWasReceived?({ error }: {
~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@apollo/server/dist/esm/externalTypes/plugins.d.ts:33:5 - error TS1005: ‘,’ expected.

33 startupDidFail?({ error }: {
~~~~~~~~~~~~~~

Found 30 errors in 2 files.

Errors Files
23 node_modules/@apollo/server/dist/esm/ApolloServer.d.ts:64
7 node_modules/@apollo/server/dist/esm/externalTypes/plugins.d.ts:20


tsconfig.json:
{
  "compilerOptions": {
    "rootDir": "src/",
    "outDir": "build",
    "target": "ES2020",
    "lib": [
      "ES2020"
    ],
    "module": "ESNext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "types": [
      "node"
    ],
    "allowJs": true,
    "strict": false,
    "sourceMap": false,
    "noImplicitAny": false,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": false,
    "allowSyntheticDefaultImports": true,
    "downlevelIteration": true,
    "resolveJsonModule": true,
    "baseUrl": "src/",
    "skipLibCheck": true
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules"
  ]
}
  

Hello! ASv4 requires Typescript 4.7.0 or higher.

1 Like

Ah, yes, I just clicked that this might be the problem after posting this. Thanks for the fast reply, much appreciated!

Am glad this seem to be resolved. I have a similar issue with apollo/client on my angular application.

Error: node_modules/@apollo/client/cache/core/types/common.d.ts:52:110 - error TS1005: ‘?’ expected.

My typescript version is “typescript”: “~4.0.2”

1 Like

are you fixed it, my version typescript is “typescript@4.5.4”, I got same error when building by docker

As mentioned above, you need to update your TS version: