graphql-subscriptions: Cannot find name 'AsyncIterator' error in Typescript compilation process.
I have found a difficulty compiling my Typescript code and it turns out that inside many files in graphql-subscriptions and subscriptions-transport-ws, the AsyncIterator iterator type interface is treated as defined, but the Typescript compiler doesn’t agree with that. here is the list of errors:
node_modules/graphql-subscriptions/dist/pubsub-engine.d.ts(5,52): error TS2304: Cannot find name 'AsyncIterator'.
node_modules/graphql-subscriptions/dist/pubsub.d.ts(12,52): error TS2304: Cannot find name 'AsyncIterator'.
node_modules/graphql-subscriptions/dist/with-filter.d.ts(2,94): error TS2304: Cannot find name 'AsyncIterator'.
node_modules/graphql-subscriptions/dist/with-filter.d.ts(3,58): error TS2304: Cannot find name 'AsyncIterator'.
node_modules/subscriptions-transport-ws/dist/server.d.ts(5,41): error TS2304: Cannot find name 'AsyncIterator'.
node_modules/subscriptions-transport-ws/dist/server.d.ts(29,58): error TS2304: Cannot find name 'AsyncIterator'.
node_modules/subscriptions-transport-ws/dist/server.d.ts(32,31): error TS2304: Cannot find name 'AsyncIterator'.
I had found a temporary solution to bypass the errors by defining AsyncIterator type interface in every file involved in node_modules, here is the definition:
interface AsyncIterator<T> {
next(value?: any): Promise<IteratorResult<T>>;
return?(value?: any): Promise<IteratorResult<T>>;
throw?(e?: any): Promise<IteratorResult<T>>;
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 38
- Comments: 54 (4 by maintainers)
Commits related to this issue
- added async iterator type stubs, see https://github.com/apollographql/graphql-subscriptions/issues/83 for more info — committed to orbiting/republik-admin-frontend by lukasbuenger 7 years ago
- Fix TS Compile error with a local dev copy of serverless: https://github.com/apollographql/graphql-subscriptions/issues/83 — committed to bakerstreet-industries/aws-ts-starter by Roustalski 7 years ago
- - add lib 'esnext' option to tsconfig.json to get rid of warning message/error, as described here: https://github.com/apollographql/graphql-subscriptions/issues/83#issuecomment-326675684 modified: ... — committed to adamcee/shuttle_code by adamcee 6 years ago
- use esnext.asynciterable See https://github.com/apollographql/graphql-subscriptions/issues/83 — committed to govau/inbox-alpha by jonathaningram 6 years ago
- https://github.com/apollographql/graphql-subscriptions/issues/83 — committed to Mellbourn/apollo-test by Mellbourn 6 years ago
- Pull in all of esnext lib (#129) Fixes #127. I'm not exactly sure why this is necessary, but seeing reports of a similar issue in another lib https://github.com/apollographql/graphql-subscriptions/is... — committed to Azure/azure-cosmos-js by southpolesteve 6 years ago
- Add support for esnext features in TS https://github.com/apollographql/graphql-subscriptions/issues/83 — committed to MatiasOlivera/feedy by MatiasOlivera 6 years ago
Thanks!! By adding:
to tsconfig.json file fixed the issue for good.
@Parziphal, agree.
I think this problem is there because of the fact that TypeScript has the default
"lib"
option defined somewhere in the code.So, in order to fix that problem, you need to include all of the libraries that
"lib"
option contains by default. Those are:So, this solves the problem, - you just need to set the
"lib"
TypeScript compiler option to the array of default libraries concatenaed with the"esnext.asynciterable"
library, like this:I also faced with the same issue:
adding “esnext” to the “lib” fixed my problem.
"lib": ["es6", "dom", "esnext"],
https://github.com/graphcool-examples/angular-graphql/pull/8/files
I think we can use
esnext
lib to fix this issue. See below linkhttps://github.com/apollographql/graphql-subscriptions/issues/77
If I add the
lib
array tocompilerOptions
, I get hundreds of errors because everything breaks (evenDate
becomes unavailable). Adding the interface to the files where the error occurs fixed the problem.+1 for major annoyance!
I had the same problem and the following change to
tsconfig.json
did the trick:skipLibCheck: true
tocompilerOptions
Example tsconfig.json:
This has become a major annoyance for me as well, having ‘fixed’ it a while ago but now it seems to be an issue again and no combination of “lib”: […] seems to work now
There are two tsconfig.json (one in root folder and another in src/ folder) files when working with an Angular app installed with CLI. The problem gets fixed when I put “esnext” within src/tsconfig.json:
"lib": [ "es2015", "dom", "esnext" ]
None of the solutions work 😃 Adding EsNext does nothing for me, throws the error on browser.
FWIW, the only fix that worked for me was this exact
tsconfig.json
:TL;DR: the only thing in
lib
isesnext
–esnext.asynciterable
alone yielded the following error:I should also note that the default library list changes when
compilerOptions.target
gets changed.So, you should probably go here, find
--lib
option, and look at the defaults which fit your needs.I stumbled upon this issue while trying the hello world tutorial for Apollo with TypeScript. Indeed just adding esnext.asynciterable fixed the issue
Just adding
esnext.asynciterable
worked for me:This is becoming a real blocker now!
I have added the
lib
stuff to the tsconfig.json and it compiles without error. But now I am loading another module via package.json that we have written ourselves (which compiles itself without errors) and it breaks thenpm install
with the same AsyncIterator Error.So each projects compiles without errors, but when I import the other project then the build fails. What is going on here?
Is there a fix on the way? It’s been a couple of months now
@danielpa9708 just
esnext
alone saves the day. But don’t know if there’s any performance loss by doing that.Thanks to @leebenson. All I had to have was only
"esnext"
.Hrm, adding the big list of options to lib didn’t work for me. I got a bunch of other errors
The only sane reply here. The question is, whether the
graphql
library uses the feature or just produces a polyfilled fake of the interface. If the later is the case, addinges2018.asynciterable
oresnext.asynciterable
tolib
in tsconfig.json is okay. If the former is the case, you need to polyfill the feature.Installing Graphql types solved my case:
npm install --save-dev @types/graphql
including it giving me error
(in promise): TypeError: Object(…) is not a function TypeError: Object(…) is not a function"
Note that there is a small risk with using “esnext” instead of “esnext.asynciterable” specifically: “esnext” will allow you to use any new JS features supported by TypeScript regardless of whether or not you have a polyfill for them. So be mindful of which ES2016+ features you’re using and use something like https://polyfill.io if you want broad browser support.
My local environment (node 6) doesn’t yet support
AsyncIterables
so I believe putting it intsconfig:lib
is incorrect and could lead to other parts of the project compiling when they shouldn’t.This project should define
AsyncIterator
with a compatible definition instead of relying on the definition from the library. This will also make less peoples projects break when they use your project.Hi guys I’m having the same problem:
ERROR in /Users/danielezurico/Downloads/angular-graphql-master/quickstart-with-apollo/node_modules/@types/graphql/subscription/subscribe.d.ts (17,4): Cannot find name 'AsyncIterator'. ERROR in /Users/danielezurico/Downloads/angular-graphql-master/quickstart-with-apollo/node_modules/@types/graphql/subscription/subscribe.d.ts (29,4): Cannot find name 'AsyncIterable'.
I tried to add
"lib": [ "es5", "es6", "dom", "es2015.core", "es2015.collection", "es2015.generator", "es2015.iterable", "es2015.promise", "es2015.proxy", "es2015.reflect", "es2015.symbol", "es2015.symbol.wellknown", "esnext.asynciterable" ]
my package.json is: https://github.com/graphcool-examples/angular-graphql/blob/master/quickstart-with-apollo/package.json