Apollo-server: Apollo-Server RC Throws Error with TypeScript

Created on 17 Jun 2018  路  13Comments  路  Source: apollographql/apollo-server

I am getting this:

api_1      | [TypeScript] node_modules/apollo-engine-reporting/lib/extension.d.ts(16,18): error TS2304: Cannot find name 'Request'.
api_1      | [TypeScript] node_modules/apollo-server-core/dist/ApolloServer.d.ts(9,49): error TS2304: Cannot find name 'RequestInit'.
api_1      | [TypeScript] node_modules/apollo-server-core/dist/logging.d.ts(29,18): error TS2304: Cannot find name 'Request'.
api_1      | [TypeScript] node_modules/apollo-server-core/dist/runHttpQuery.d.ts(6,19): error TS2304: Cannot find name 'Request'.
api_1      | [TypeScript] node_modules/apollo-server-core/dist/runQuery.d.ts(28,19): error TS2304: Cannot find name 'Request'.
api_1      | [TypeScript] node_modules/apollo-server-core/dist/types.d.ts(15,55): error TS2304: Cannot find name 'WebSocket'.
api_1      | [TypeScript] node_modules/apollo-server-core/dist/types.d.ts(16,32): error TS2304: Cannot find name 'WebSocket'.
api_1      | [TypeScript] node_modules/apollo-server/dist/index.d.ts(1,23): error TS2688: Cannot find type definition file for 'express'.
api_1      | [TypeScript] node_modules/apollo-server/dist/index.d.ts(2,10): error TS2305: Module '"/usr/app/node_modules/express/index"' has no exported member 'Request'.
api_1      | [TypeScript] node_modules/graphql-extensions/lib/index.d.ts(10,18): error TS2304: Cannot find name 'Request'.
api_1      | [TypeScript] node_modules/graphql-extensions/lib/index.d.ts(38,18): error TS2304: Cannot find name 'Request'.
api_1      | [TypeScript] node_modules/subscriptions-transport-ws/dist/server.d.ts(20,13): error TS2304: Cannot find name 'WebSocket'.
api_1      | [TypeScript] node_modules/subscriptions-transport-ws/dist/server.d.ts(70,58): error TS2503: Cannot find namespace 'WebSocket'.
api_1      | [TypeScript] node_modules/subscriptions-transport-ws/dist/server.d.ts(71,56): error TS2503: Cannot find namespace 'WebSocket'.
api_1      | [TypeScript] node_modules/subscriptions-transport-ws/dist/server.d.ts(72,22): error TS2503: Cannot find namespace 'WebSocket'.

when I am trying to use Apollo-Server ^2.0.0-beta.7 in a Typescript ^2.9.2 based project. The following is the package.json

{
  "name": "somename",
  "version": "1.0.0",
  "main": "dist/src/index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "npm run serve",
    "build": "npm run build-ts && npm run tslint",
    "serve": "node dist/src/index.js",
    "watch-node": "nodemon dist/src/index.js",
    "watch": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold\" \"npm run watch-ts\" \"npm run watch-node\"",
    "watch-test": "npm run test -- --watchAll",
    "build-ts": "tsc",
    "watch-ts": "tsc -w",
    "tslint": "tslint -c tslint.json -p tsconfig.json",
    "debug": "npm run build && npm run watch-debug",
    "serve-debug": "nodemon --inspect dist/server.js",
    "watch-debug": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold\" \"npm run watch-ts\" \"npm run serve-debug\""
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/someuser/some-api.git"
  },
  "dependencies": {
    "apollo-server": "^2.0.0-beta.7",
    "graphql": "^0.13.2",
    "graphql-tag": "^2.9.2",
    "knex": "^0.14.6",
    "moment": "^2.22.2",
    "node-fetch": "^2.1.2",
    "objection": "^1.1.10",
    "pg": "^7.4.3"
  },
  "devDependencies": {
    "@types/graphql": "^0.13.1",
    "@types/knex": "^0.14.14",
    "@types/node": "^10.3.3",
    "@types/node-fetch": "^2.1.1",
    "@types/pg": "^7.4.9",
    "concurrently": "^3.5.1",
    "nodemon": "^1.17.5",
    "prettier": "1.13.5",
    "ts-node": "^6.1.1",
    "tslint": "^5.10.0",
    "tslint-config-prettier": "^1.13.0",
    "typescript": "^2.9.2"
  }
}

Am I missing something obvious?

has-reproduction

Most helpful comment

workaround:

skipLibCheck: true to compilerOptions hides the issue

All 13 comments

Updated to RC, now seeing this:

[TypeScript] node_modules/apollo-engine-reporting/lib/extension.d.ts(2,28): error TS2305: Module '"/Users/someuser/someapi/node_modules/graphql-extensions/lib/index"' has no exported member 'GraphQLResponse'.
[TypeScript] node_modules/apollo-engine-reporting/lib/extension.d.ts(2,45): error TS2305: Module '"/Users/someuser/someapi/node_modules/graphql-extensions/lib/index"' has no exported member 'EndHandler'.
[TypeScript] node_modules/apollo-engine-reporting/lib/extension.d.ts(15,5): error TS2416: Property 'requestDidStart' in type 'EngineReportingExtension<TContext>' is not assignable to the same property in base type 'GraphQLExtension<TContext>'.
[TypeScript]   Type '(o: { request: Request; queryString?: string; parsedQuery?: DocumentNode; variables: Record<strin...' is not assignable to type '() => void'.
[TypeScript] node_modules/apollo-engine-reporting/lib/extension.d.ts(21,5): error TS2416: Property 'executionDidStart' in type 'EngineReportingExtension<TContext>' is not assignable to the same property in base type 'GraphQLExtension<TContext>'.
[TypeScript]   Type '(o: { executionArgs: ExecutionArgs; }) => void' is not assignable to type '() => void'.
[TypeScript] node_modules/apollo-engine-reporting/lib/extension.d.ts(24,5): error TS2416: Property 'willResolveField' in type 'EngineReportingExtension<TContext>' is not assignable to the same property in base type 'GraphQLExtension<TContext>'.
[TypeScript]   Type '(_source: any, _args: { [argName: string]: any; }, _context: TContext, info: GraphQLResolveInfo) ...' is not assignable to type '(source: any, args: { [argName: string]: any; }, context: TContext, info: GraphQLResolveInfo) => ...'.
[TypeScript]     Type 'void | ((error: Error, result: any) => void)' is not assignable to type 'void | ((result: any) => void)'.
[TypeScript]       Type '(error: Error, result: any) => void' is not assignable to type 'void | ((result: any) => void)'.
[TypeScript]         Type '(error: Error, result: any) => void' is not assignable to type '(result: any) => void'.
[TypeScript] node_modules/apollo-server/node_modules/apollo-server-core/dist/logging.d.ts(1,28): error TS2305: Module '"/Users/someuser/someapi/node_modules/graphql-extensions/lib/index"' has no exported member 'GraphQLResponse'.
[TypeScript] node_modules/apollo-server/node_modules/apollo-server-core/dist/logging.d.ts(28,5): error TS2416: Property 'requestDidStart' in type 'LogFunctionExtension<TContext>' is not assignable to the same property in base type 'GraphQLExtension<TContext>'.
[TypeScript]   Type '(options: { request: Request; queryString?: string; parsedQuery?: DocumentNode; operationName?: s...' is not assignable to type '() => void'.
[TypeScript] node_modules/apollo-server/node_modules/apollo-server-core/dist/types.d.ts(15,55): error TS2304: Cannot find name 'WebSocket'.
[TypeScript] node_modules/apollo-server/node_modules/apollo-server-core/dist/types.d.ts(16,32): error TS2304: Cannot find name 'WebSocket'.
[TypeScript] node_modules/apollo-server/node_modules/apollo-server-express/dist/ApolloServer.d.ts(11,12): error TS2503: Cannot find namespace 'corsMiddleware'.
[TypeScript] node_modules/subscriptions-transport-ws/dist/server.d.ts(20,13): error TS2304: Cannot find name 'WebSocket'.
[TypeScript] node_modules/subscriptions-transport-ws/dist/server.d.ts(70,66): error TS2503: Cannot find namespace 'WebSocket'.
[TypeScript] node_modules/subscriptions-transport-ws/dist/server.d.ts(70,92): error TS2503: Cannot find namespace 'WebSocket'.
[TypeScript] node_modules/subscriptions-transport-ws/dist/server.d.ts(71,64): error TS2503: Cannot find namespace 'WebSocket'.
[TypeScript] node_modules/subscriptions-transport-ws/dist/server.d.ts(71,90): error TS2503: Cannot find namespace 'WebSocket'.
[TypeScript] node_modules/subscriptions-transport-ws/dist/server.d.ts(72,22): error TS2503: Cannot find namespace 'WebSocket'.

@naishe If you add esModuleInterop: true to your tsconfig.json, does that fix things?

Hey, thanks for the response.
Yes, that's true. Here is full tsconfig.json

{
  "compilerOptions": {
    "target": "es2017" ,
    "module": "commonjs" ,
    "lib": [
      "es2017",
      "esnext.asynciterable"
    ] ,
    "allowJs": true ,
    "sourceMap": true ,
    "outDir": "./dist" ,    
    "noUnusedLocals": true ,
    "noUnusedParameters": true ,
    "noImplicitReturns": true ,
    "noFallthroughCasesInSwitch": true ,
    "moduleResolution": "node" ,
    "baseUrl": "./" ,
    "paths": {
      "*": ["node_modules/*", "src/types/*"]
    } ,
    "allowSyntheticDefaultImports": true ,
    "esModuleInterop": true 
  },
  "include": ["src*"]
}

workaround:

skipLibCheck: true to compilerOptions hides the issue

@naishe Great to hear! For the next release, we'll be setting esModuleInterop to false, so that user code does not need to set esModuleInterop as well.

Hey @evans, sorry for miscommunication. It's the skipLibCheck: true that suppressed the warnings. Maybe along with esModuleInterop because it was always on.

We've fixed this in RC.1 to not require esModuleInterop. I've tested compilation locally with symlinks, so I feel comfortable closing the issue. Let me know if you run into more problems!

Thank you again @naishe for opening the issue!

I'm seeing this in rc5, even with esModuleInterop: true in tsconfig.

node_modules/apollo-engine-reporting/lib/extension.d.ts(2,28): error TS2305: Module '"/usr/src/app/node_modules/graphql-extensions/lib/index"' has no exported member 'GraphQLResponse'.
node_modules/apollo-engine-reporting/lib/extension.d.ts(2,45): error TS2305: Module '"/usr/src/app/node_modules/graphql-extensions/lib/index"' has no exported member 'EndHandler'.
node_modules/apollo-engine-reporting/lib/extension.d.ts(15,5): error TS2416: Property 'requestDidStart' in type 'EngineReportingExtension<TContext>' is not assignable to the same property in base type 'GraphQLExtension<TContext>'.

@altschuler, I think you and @naishe are now facing a different issue. You should probably open a new one (and refer to this). (not reproduced for me with rc5)

hmm @amitport + @evans so I was able to suppress this alert using "skipLibCheck": true as mentioned above...but this feels like a work around more so than a solution. Has a finalized solution been found for this issue?

I have the same problem :/

This issue still exists. Did anybody find solution yet?

node_modules/apollo-server-express/node_modules/apollo-server-core/dist/plugin/index.d.ts:3:1 - error TS1128: Declaration or statement expected.

I have the same issue

Was this page helpful?
0 / 5 - 0 ratings