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

TypeScript import issues with apollo-server-express #927

Closed
dsebastien opened this Issue Mar 30, 2018 · 11 comments

Comments

Projects
None yet
@dsebastien

dsebastien commented Mar 30, 2018

Hello,

Yesterday while I was trying out Apollo for the first time with express and TypeScript, I've stumbled upon the following issue when compiling using TSC:

node_modules/apollo-cache-control/lib/index.d.ts(20,16): error TS2665: Invalid module name in augmentation. Module 'graphql/type/definition' resolves to an untyped module at 'C:/dev/wks/bedeals-mvp/functions/node_modules/graphql/type/definition.js', which cannot be augmented..

At first I filed apollographql/apollo-cache-control#4 but then realized that my imports were causing the issue.

This import causes the issue with TypeScript: import {graphiqlExpress, graphqlExpress} from "apollo-server-express"; while it works fine with this one: const {graphqlExpress, graphiqlExpress} = require('apollo-server-express');.

You may say "that's the way to import it", but the first import was added for me by IntelliJ's auto-import, which is why I found this to be disturbing. I wasted a lot of time thinking that my node_modules folder wasn't okay, that my TSC version or config was incorrect, ...

It would be nice to have better TypeScript support

@stanleyeosakul

This comment has been minimized.

stanleyeosakul commented Apr 1, 2018

Nice fix! I agree, I wish there was better Typescript support.

@glasser

This comment has been minimized.

Contributor

glasser commented Apr 2, 2018

I'm not sure that I follow — shouldn't we support import if your TS/Node is otherwise set up to support it?

I'll note that I saw a version of this error myself while working on creating apollo-cache-control@0.1.0 but it resolved itself after... running npm install inside apollo-server-core. I thought maybe it was just an artifact of our lerna setup but if it's affecting end users, that's an issue.

abernix added a commit that referenced this issue Apr 10, 2018

Convert `Buffer.byteLength` to string before assigning to `Content-Le…
…ngth`.

This change seems necessary in order to meet the new type definitions for
`res.setHeader` which mandate that the argument be a string, or an array of
strings.  Those type definitions were introduced via the `@types/node@9`
series of typing updates provided in [0], [1], [2].

With any luck, this will fix the failures being exhibited in CircleCI
tests[3] after we landed those typing updates.

[0]: #907
[1]: #927
[2]: #939
[3]: https://circleci.com/gh/apollographql/apollo-server/1587

abernix added a commit that referenced this issue Apr 11, 2018

Convert `Buffer.byteLength` to string before assigning to `Content-Le…
…ngth`. (#956)

This change seems necessary in order to meet the new type definitions for
`res.setHeader` which mandate that the argument be a string, or an array of
strings.  Those type definitions were introduced via the `@types/node@9`
series of typing updates provided in [0], [1], [2].

With any luck, this will fix the failures being exhibited in CircleCI
tests[3] after we landed those typing updates.

[0]: #907
[1]: #927
[2]: #939
[3]: https://circleci.com/gh/apollographql/apollo-server/1587
@whatupdave

This comment has been minimized.

whatupdave commented May 3, 2018

I fixed it by installing the types for graphql

npm i --save-dev @types/graphql
@abernix

This comment has been minimized.

Member

abernix commented Sep 20, 2018

Can anyone confirm that this is still a problem for them with Apollo Server 2?

While this issue has a number of up-votes, it's gone otherwise silent and it's hard to determine if this problem is still affecting users so we can prioritize accordingly.

Feedback would be appreciated!

@hwillson

This comment has been minimized.

Member

hwillson commented Sep 26, 2018

Sounds like this has been resolved. Let us know if this is still an issue. Thanks!

@hwillson hwillson closed this Sep 26, 2018

@AleksandarFaraj

This comment has been minimized.

AleksandarFaraj commented Sep 29, 2018

@abernix I just got this issue and fixed it using whatupdave's solution. It seems it could be easily fixable by just including @types/graphql as a dependency for the cache-control package?

@kachkaev

This comment has been minimized.

kachkaev commented Oct 4, 2018

Same thing here as @AleksandarFaraj describes. Using apollo-server 2.1.0.

@cmcaboy

This comment has been minimized.

cmcaboy commented Nov 17, 2018

This fixed my issue! Thank you so much @dsebastien!

@Vheissu

This comment has been minimized.

Vheissu commented Nov 29, 2018

Installing the types as mentioned above fixes the issue.

@brianalois

This comment has been minimized.

brianalois commented Dec 5, 2018

This is still a problem for me
"apollo-server-express": "^2.1.0"
"typescript": "^3.1.2"
"@types/graphql": "^14.0.3",

NEED HELP

@kachkaev

This comment has been minimized.

kachkaev commented Dec 9, 2018

Here's the output of my linting tsc, even after installing @types/graphql:

node_modules/apollo-server-core/dist/types.d.ts:4:8 - error TS1192: Module '"/path/to/graphql-servera/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 '"/path/to/graphql-server/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 '"/path/to/graphql-server/node_modules/@types/cors/index"' has no default export.

2 import corsMiddleware from 'cors';

Adding "skipLibCheck": true, has helped as a workaround, but the issue is still topical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment