Graphql: Compile error coming from apollo-server-core/dist/ApolloServer.d.ts

Created on 8 May 2020  ยท  8Comments  ยท  Source: nestjs/graphql

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I am getting the following build error after bumping to 7.3.7:

> nest build

node_modules/apollo-server-core/dist/ApolloServer.d.ts:5:8 - error TS1259: Module '"/Users/dev/proj/node_modules/@types/ws/index"' can only be default-imported using the 'esModuleInterop' flag

5 import WebSocket from 'ws';
         ~~~~~~~~~

  node_modules/@types/ws/index.d.ts:270:1
    270 export = WebSocket;
        ~~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

Found 1 error(s).

Expected behavior

No errors during build

Minimal reproduction of the problem with instructions

I can't reproduce that on a clean nest app, however running npm list apollo-server-core clearly states that the lib causing this error is comming from a dependency of @nestjs/graphql:

โ”œโ”€โ”ฌ @nestjs/[email protected]
โ”‚ โ””โ”€โ”ฌ @apollo/[email protected]
โ”‚ โ””โ”€โ”€ [email protected]
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ””โ”€โ”€ [email protected]
โ””โ”€โ”ฌ [email protected]
โ””โ”€โ”€ [email protected]

Seems that adding skipLibCheck to tsconfig resolves this problem

Environment


Nest version: 7.3.7


For Tooling issues:
- Node version: 12.13  
- Platform:  Mac 

Others:

needs clarification

Most helpful comment

  • Node version: 10.16.3
  • Platform: Mac
  • Nestjs: 7.0.11

Hi!
I'm trying install a clean version with graphql:

nest new test
npm i --save @nestjs/graphql graphql-tools graphql

after that import GraphQLModule in AppModule

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { GraphQLModule } from '@nestjs/graphql';

@Module({
  imports: [GraphQLModule.forRoot({})],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

to run with npm start get the error

node_modules/apollo-server-core/dist/ApolloServer.d.ts:5:8 - error TS1259: Module '"/Users/josecarlos.rodriguez/Documents/projects/nestjs/test/node_modules/@types/ws/index"' can only be default-imported using the 'esModuleInterop' flag

5 import WebSocket from 'ws';
         ~~~~~~~~~

  node_modules/@types/ws/index.d.ts:270:1
    270 export = WebSocket;
        ~~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

All 8 comments

Please provide a minimum reproduction repository. This doesn't seem to be specifically related to NestJS, but rather to the underlying apollo-server-express library.

  • Node version: 10.16.3
  • Platform: Mac
  • Nestjs: 7.0.11

Hi!
I'm trying install a clean version with graphql:

nest new test
npm i --save @nestjs/graphql graphql-tools graphql

after that import GraphQLModule in AppModule

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { GraphQLModule } from '@nestjs/graphql';

@Module({
  imports: [GraphQLModule.forRoot({})],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

to run with npm start get the error

node_modules/apollo-server-core/dist/ApolloServer.d.ts:5:8 - error TS1259: Module '"/Users/josecarlos.rodriguez/Documents/projects/nestjs/test/node_modules/@types/ws/index"' can only be default-imported using the 'esModuleInterop' flag

5 import WebSocket from 'ws';
         ~~~~~~~~~

  node_modules/@types/ws/index.d.ts:270:1
    270 export = WebSocket;
        ~~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

add this in your tsconfig.json

"allowSyntheticDefaultImports": true

add this in your tsconfig.json

"allowSyntheticDefaultImports": true

That's a bit of a bomb that will influence how imports are handled in all the other places in your app so I would proceed with caution

With this option get a waterfall errors:

The "apollo-server-express" package is missing. Please, make sure to install this library ($ npm install apollo-server-express) to take advantage of GraphQLModule.

after install apollo-server-express

(node:46945) UnhandledPromiseRejectionWarning: Error: Apollo Server requires either an existing schema, modules or typeDefs
    at ApolloServer.initSchema (/Users/josecarlos.rodriguez/Documents/projects/nestjs/test/node_modules/apollo-server-core/dist/ApolloServer.js:241:23)
    at new ApolloServerBase (/Users/josecarlos.rodriguez/Documents/projects/nestjs/test/node_modules/apollo-server-core/dist/ApolloServer.js:196:30)
    at new ApolloServer (/Users/josecarlos.rodriguez/Documents/projects/nestjs/test/node_modules/apollo-server-express/dist/ApolloServer.js:59:9)
    at GraphQLModule.registerExpress (/Users/josecarlos.rodriguez/Documents/projects/nestjs/test/node_modules/@nestjs/graphql/dist/graphql.module.js:118:30)
    at GraphQLModule.registerGqlServer (/Users/josecarlos.rodriguez/Documents/projects/nestjs/test/node_modules/@nestjs/graphql/dist/graphql.module.js:103:18)
    at GraphQLModule.<anonymous> (/Users/josecarlos.rodriguez/Documents/projects/nestjs/test/node_modules/@nestjs/graphql/dist/graphql.module.js:93:18)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/josecarlos.rodriguez/Documents/projects/nestjs/test/node_modules/@nestjs/graphql/node_modules/tslib/tslib.js:110:62)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
(node:46945) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:46945) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I think this issue should be reported in the Apollo repository. We can't really do anything about this, unfortunately.

For anyone who is blocked by this issue, please, set skipLibCheck to true in your tsconfig.json file. Alternatively, you can see the esModuleInterop to true (as suggested here https://github.com/apollographql/apollo-server/issues/1977#issuecomment-487012924) BUT this can affect your app

add this in your tsconfig.json

"allowSyntheticDefaultImports": true

all works good, but when I try to start my server inside the docker, I had this "Error: socket hang up" in postman

and this in the console

Screenshot 2020-05-28 at 13 39 12

also, API doesn't work on the AWS

apollo-server-express: 2.14.0

Does someone have any solution?

@Baksha2008 on your tsconfig.json add skipLibCheck": true

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jiayechao picture jiayechao  ยท  4Comments

harm-less picture harm-less  ยท  4Comments

galkin picture galkin  ยท  4Comments

ghost picture ghost  ยท  5Comments

cschroeter picture cschroeter  ยท  3Comments