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

[apollo-server-koa] Has no default import #2110

Closed
messenger91 opened this issue Dec 18, 2018 · 8 comments
Closed

[apollo-server-koa] Has no default import #2110

messenger91 opened this issue Dec 18, 2018 · 8 comments

Comments

@messenger91
Copy link

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.
@dortamiguel
Copy link
Contributor

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';
         ~~~~~~~~~~~~~~

@messenger91
Copy link
Author

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

@messenger91
Copy link
Author

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

@anymost
Copy link

anymost commented Apr 1, 2019

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

@messenger91
Copy link
Author

@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.

@anymost
Copy link

anymost commented Apr 2, 2019

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.

@anymost
Copy link

anymost commented Apr 2, 2019

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

@abernix
Copy link
Member

abernix commented Apr 26, 2019

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.

@abernix abernix closed this as completed Apr 26, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
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