Apollo-server: [apollo-server-koa] Has no default import

Created on 18 Dec 2018  路  8Comments  路  Source: apollographql/apollo-server

apollo-server-koa: 2.3.1
Description: Can't build and compile files while in core package types has wrong imports
Error log:

node_modules/apollo-server-koa/dist/ApolloServer.d.ts:1:8 - error TS1192: Module '"/usr/src/gateway/node_modules/@types/koa/index"' has no default export.

1 import Koa from 'koa';
         ~~~

node_modules/apollo-server-koa/dist/ApolloServer.d.ts:2:8 - error TS1192: Module '"/usr/src/gateway/node_modules/@types/koa__cors/index"' has no default export.

2 import corsMiddleware from '@koa/cors';
         ~~~~~~~~~~~~~~

node_modules/apollo-server-koa/dist/ApolloServer.d.ts:3:8 - error TS1192: Module '"/usr/src/gateway/node_modules/@types/koa-bodyparser/index"' has no default export.

3 import bodyParser from 'koa-bodyparser';
         ~~~~~~~~~~

node_modules/apollo-server-koa/node_modules/apollo-server-core/dist/types.d.ts:4:8 - error TS1192: Module '"/usr/src/gateway/node_modules/@types/ws/index"' has no default export.

4 import WebSocket from 'ws';
         ~~~~~~~~~


Found 4 errors.

Most helpful comment

Same here also in apollo-server-express

node_modules/apollo-server-core/dist/types.d.ts:4:8 - error TS1192: Module '"/Users/miguel/src/sam-labs-api/node_modules/@types/ws/index"' has no default export.

4 import WebSocket from 'ws';
         ~~~~~~~~~

node_modules/apollo-server-express/dist/ApolloServer.d.ts:1:8 - error TS1192: Module '"/Users/miguel/src/sam-labs-api/node_modules/@types/express/index"' has no default export.

1 import express from 'express';
         ~~~~~~~

node_modules/apollo-server-express/dist/ApolloServer.d.ts:2:8 - error TS1192: Module '"/Users/miguel/src/sam-labs-api/node_modules/@types/cors/index"' has no default export.

2 import corsMiddleware from 'cors';
         ~~~~~~~~~~~~~~

All 8 comments

Same here also in apollo-server-express

node_modules/apollo-server-core/dist/types.d.ts:4:8 - error TS1192: Module '"/Users/miguel/src/sam-labs-api/node_modules/@types/ws/index"' has no default export.

4 import WebSocket from 'ws';
         ~~~~~~~~~

node_modules/apollo-server-express/dist/ApolloServer.d.ts:1:8 - error TS1192: Module '"/Users/miguel/src/sam-labs-api/node_modules/@types/express/index"' has no default export.

1 import express from 'express';
         ~~~~~~~

node_modules/apollo-server-express/dist/ApolloServer.d.ts:2:8 - error TS1192: Module '"/Users/miguel/src/sam-labs-api/node_modules/@types/cors/index"' has no default export.

2 import corsMiddleware from 'cors';
         ~~~~~~~~~~~~~~

Same here also in apollo-server-express

node_modules/apollo-server-core/dist/types.d.ts:4:8 - error TS1192: Module '"/Users/miguel/src/sam-labs-api/node_modules/@types/ws/index"' has no default export.

4 import WebSocket from 'ws';
         ~~~~~~~~~

node_modules/apollo-server-express/dist/ApolloServer.d.ts:1:8 - error TS1192: Module '"/Users/miguel/src/sam-labs-api/node_modules/@types/express/index"' has no default export.

1 import express from 'express';
         ~~~~~~~

node_modules/apollo-server-express/dist/ApolloServer.d.ts:2:8 - error TS1192: Module '"/Users/miguel/src/sam-labs-api/node_modules/@types/cors/index"' has no default export.

2 import corsMiddleware from 'cors';
         ~~~~~~~~~~~~~~

I just make a patch with normal import and rewrite that files to correct and after this - build successful

@ellipticaldoor I create gists with patching this issue. apollo-server-koa+2.3.1.patch and apollo-server-core+2.3.1.patch

The same issue I encountered, so how do I fix it?

@anymost Just update apollo-server version in your package.json. Need >= 2.4.3 version or create patch in your project if you still have old version < 2.4.3 version. See above my example patch for that issue.

The version of apollo-server-koa I used is 2.4.8. The error happened when I use tsc to build the program. But when I use ts-node to development, The error wouldn't happened.

@doroninds Finally, I fixed the error by upgrading @types/graphql and setting "esModuleInterop" to true in tsconfig.json

Relates-to or duplicated-by #1977, #2519, #2521 (and more).

Thanks so much for opening this originally. The important thing here is that the consuming project needs to adopt esModuleInterop: true. While enabling esModuleInterop within Apollo Server was more of a breaking change than intended (or even understood, at the time it was done), it's been almost a year now since it was first enabled. This flag first became available in TypeScript 2.7 and helps align TypeScript with the behavior chosen by Babel, Webpack, Rollup, React Native, etc. It's been the default configuration generated by tsc --init for quite some time and at this point we're intending to stick with esModuleInterop: true going forward.

It _may_ be possible to avoid the type errors on an existing project by enabling allowSyntheticDefaultImports (which doesn't change the code emitted, just changes the type-checking behavior), but I haven't verified.

Was this page helpful?
0 / 5 - 0 ratings