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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't compile with "error TS2304: Cannot find name 'AsyncGenerator'" (or 'AsyncIterable') #131

Closed
bananaumai opened this issue Oct 1, 2020 · 7 comments

Comments

@bananaumai
Copy link
Contributor

Hi, I'm really new to msgpack-javasript. I'm appreciated your great works first 馃槃

I'm facing errors saying like "error TS2304: Cannot find name 'AsyncGenerator'" when I compile my ts code with tsc.

My environment is something like below.

package.json

{
  "name": "msgpack",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@msgpack/msgpack": "^2.1.0",
    "typescript": "^4.0.3"
  }
}

tsconfig.jso

{
    "compilerOptions": {
        "moduleResolution": "node",
        "lib": ["ES2018", "DOM"]
    }
}

index.ts

import { encode } from "@msgpack/msgpack";

const encoded: Uint8Array = encode({ foo: "bar" });
console.log(encoded);

The following is the full error messages:

$ npx tsc index.ts
node_modules/@msgpack/msgpack/dist/decodeAsync.d.ts:5:162 - error TS2304: Cannot find name 'AsyncGenerator'.

5 export declare function decodeArrayStream<ContextType>(streamLike: ReadableStreamLike<ArrayLike<number>>, options?: DecodeOptions<SplitUndefined<ContextType>>): AsyncGenerator<unknown, void, unknown>;
                                                                                                                                                                   ~~~~~~~~~~~~~~

node_modules/@msgpack/msgpack/dist/decodeAsync.d.ts:6:157 - error TS2304: Cannot find name 'AsyncGenerator'.

6 export declare function decodeStream<ContextType>(streamLike: ReadableStreamLike<ArrayLike<number>>, options?: DecodeOptions<SplitUndefined<ContextType>>): AsyncGenerator<unknown, void, unknown>;
                                                                                                                                                              ~~~~~~~~~~~~~~

node_modules/@msgpack/msgpack/dist/Decoder.d.ts:27:25 - error TS2304: Cannot find name 'AsyncIterable'.

27     decodeAsync(stream: AsyncIterable<ArrayLike<number>>): Promise<unknown>;
                           ~~~~~~~~~~~~~

node_modules/@msgpack/msgpack/dist/Decoder.d.ts:28:31 - error TS2304: Cannot find name 'AsyncIterable'.

28     decodeArrayStream(stream: AsyncIterable<ArrayLike<number>>): AsyncGenerator<unknown, void, unknown>;
                                 ~~~~~~~~~~~~~

node_modules/@msgpack/msgpack/dist/Decoder.d.ts:28:66 - error TS2304: Cannot find name 'AsyncGenerator'.

28     decodeArrayStream(stream: AsyncIterable<ArrayLike<number>>): AsyncGenerator<unknown, void, unknown>;
                                                                    ~~~~~~~~~~~~~~

node_modules/@msgpack/msgpack/dist/Decoder.d.ts:29:26 - error TS2304: Cannot find name 'AsyncIterable'.

29     decodeStream(stream: AsyncIterable<ArrayLike<number>>): AsyncGenerator<unknown, void, unknown>;
                            ~~~~~~~~~~~~~

node_modules/@msgpack/msgpack/dist/Decoder.d.ts:29:61 - error TS2304: Cannot find name 'AsyncGenerator'.

29     decodeStream(stream: AsyncIterable<ArrayLike<number>>): AsyncGenerator<unknown, void, unknown>;
                                                               ~~~~~~~~~~~~~~

node_modules/@msgpack/msgpack/dist/utils/stream.d.ts:1:45 - error TS2304: Cannot find name 'AsyncIterable'.

1 export declare type ReadableStreamLike<T> = AsyncIterable<T> | ReadableStream<T>;
                                              ~~~~~~~~~~~~~

node_modules/@msgpack/msgpack/dist/utils/stream.d.ts:2:86 - error TS2304: Cannot find name 'AsyncIterable'.

2 export declare function isAsyncIterable<T>(object: ReadableStreamLike<T>): object is AsyncIterable<T>;
                                                                                       ~~~~~~~~~~~~~

node_modules/@msgpack/msgpack/dist/utils/stream.d.ts:3:80 - error TS2304: Cannot find name 'AsyncIterable'.

3 export declare function asyncIterableFromStream<T>(stream: ReadableStream<T>): AsyncIterable<T>;
                                                                                 ~~~~~~~~~~~~~

node_modules/@msgpack/msgpack/dist/utils/stream.d.ts:4:83 - error TS2304: Cannot find name 'AsyncIterable'.

4 export declare function ensureAsyncIterabe<T>(streamLike: ReadableStreamLike<T>): AsyncIterable<T>;
                                                                                    ~~~~~~~~~~~~~

It would be appreciated if you give me any advise. Thanks.

@mcclure
Copy link

mcclure commented Oct 1, 2020

I am not connected with the msgpack-javascript project, I am a user. I cannot reproduce your error but I think that is because I am using Web instead of node.

According to several github issues on other projects, the solution is to add "es2018.asynciterable" to your lib array in tsconfig.json. Does that help?

If that fixes the problem, maybe msgpack should document this issue somehow.

@bananaumai
Copy link
Contributor Author

@mcclure Thank you for your advice.

I tried as you suggested:

 {
     "compilerOptions": {
         "moduleResolution": "node",
-        "lib": ["ES2018", "DOM"]
+        "lib": ["ES2018.AsyncIterable", "ES2018.AsyncGenerator", "DOM"]
     }
 }

But, it didn't work for me, unfortunately. Thanks anyway!

@gfx
Copy link
Member

gfx commented Oct 3, 2020

Can you try "lib": ["es2020"]? This is used in

"lib": ["es2020", "dom"], /* Specify library files to be included in the compilation. */

@bananaumai
Copy link
Contributor Author

@gfx Thanks for following up. I also try that way. But, again, it didn't work...

I'll give this issue some more investigation later.

@bananaumai
Copy link
Contributor Author

Uh-oh,,,,, it was just the issue of the way to compile...

npx tsc --build tsconfig.json completely has worked.

This issue was just due to my lack of understanding on tsc.

I'm sorry and thanks again for your help @gfx , @mcclure .

@gfx
Copy link
Member

gfx commented Oct 3, 2020

Excellent!

Anyway, I've mentioned to prerequisites about TypeScript in README.md: 6d2c4bc

@bananaumai
Copy link
Contributor Author

I've seen your commit, that must be really helpful. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants