winnekes/itypescript

Generator not supported

dclong opened this issue · 13 comments

The following simple code won't run in iTypeScript notebook.

function* fib(){
    yield 1;
    yield 2;
    let x1 = 1; 
    let x2 = 2;
    while(true){
        let x = x1 + x2;
        x1 = x2;
        x2 = x;
        yield x;
    }
}

The Error message is as below.

TypeError: Cannot read property 'length' of null
    at /usr/local/lib/node_modules/itypescript/lib/kernel.js:136:40
    at Array.map (<anonymous>)
    at Session.transpile (/usr/local/lib/node_modules/itypescript/lib/kernel.js:134:42)
    at Session._runNow (/usr/local/lib/node_modules/itypescript/node_modules/nel/lib/nel.js:786:39)
    at Session._run (/usr/local/lib/node_modules/itypescript/node_modules/nel/lib/nel.js:756:14)
    at Session.execute (/usr/local/lib/node_modules/itypescript/node_modules/nel/lib/nel.js:880:10)
    at Kernel.execute_request (/usr/local/lib/node_modules/itypescript/node_modules/jp-kernel/lib/handlers_v5.js:116:18)
    at Kernel.onShellMessage (/usr/local/lib/node_modules/itypescript/node_modules/jp-kernel/lib/jp-kernel.js:277:41)
    at Socket.<anonymous> (/usr/local/lib/node_modules/itypescript/node_modules/jmp/index.js:350:17)
    at Socket.emit (events.js:182:13)

Sorry for the late reply. The previous implementation was not reliable to handle some features of Typescript. This was the problem which your code was not running in ITypescript Notebook.
I updated the ITypescript to 0.3.0, which will use official typescript compiler for transpiling the code.
I checked that the code now works correctly. Here's my code for checking the functionality:

function* fib(){
    yield 1;
    yield 2;
    let x1 = 1; 
    let x2 = 2;
    while(true){
        let x = x1 + x2;
        x1 = x2;
        x2 = x;
        yield x;
    }
}
let gen = fib();
gen.next();
gen.next();
function* fib(){
    yield 1;
    yield 2;
    let x1 = 1; 
    let x2 = 2;
    while(true){
        let x = x1 + x2;
        x1 = x2;
        x2 = x;
        yield x;
    }
}
Error: Cannot find global type 'IterableIterator'.
    at execTranspile (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/lib/kernel.js:190:27)
    at Session.transpiler [as transpile] (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/lib/kernel.js:229:37)
    at Session._runNow (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/nel/lib/nel.js:796:39)
    at Session._run (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/nel/lib/nel.js:766:14)
    at Session.execute (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/nel/lib/nel.js:890:10)
    at Kernel.execute_request (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/jp-kernel/lib/handlers_v5.js:116:18)
    at Kernel.onShellMessage (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/jp-kernel/lib/jp-kernel.js:285:41)
    at Socket.<anonymous> (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/jmp/index.js:350:17)
    at Socket.emit (events.js:189:13)
    at Socket._emitMessage (/Users/umair/.nvm/versions/node/v10.15.1/lib/node_modules/itypescript/node_modules/zeromq/lib/index.js:640:15)

May be I am using different version of node?

Could you write down (1) the version of node and typescript, and (2) tsconfig.json that you're using? Then I'll try to replicate the issue.

Note: the codes in this thread were tested using Node.js 10.x and Typescript 3.3, with tsconfig.json here

@nearbydelta I encounter the same issue. Below are the versions of the related tools.

NodeJS: v10.15.0
TypeSciript: 3.3
tsconfig.json (in the same directory as my iTypeScript notebook)

{
    "module": "commonjs",
    "target": "es6",
    "moduleResolution": "nodejs",
    "esModuleInterop": true
}

@dclong Thanks for the configuration file. I successfully reproduced the issue.

The incomplete parsing process of tsconfig.json file was the cause. I should use the Enum provided by the typescript library, but I forgot to apply them. I mistakenly believed that the function ts.readConfigFile that is currently ITypescript called for parsing configuration can handle the Enum. In a couple of minutes, I'll upload a version that the function call is replaced with ts.getParsedCommandLineOfConfigFile, which correctly handles the issue. (The codes are tested with the same configuration)

@nearbydelta I still encounter the issue. What's more, the kernel keeps in Busy status after I run the code. Can we open this issue and investigate further?

image

@dclong I'd say reinstall everything including node, npm, typescript and itypescript and install globally.

@nearbydelta @umrashrf I'm using Docker and the tools are installed using root in the Docker image. I still experience issues with iTypeScript while the Python 3 and iJavaScript kernels work well.

@dclong If you don't mind, can I download your docker file? The investigation is a lot more easier if it is possible, I think.

@nearbydelta
The repository is at https://cloud.docker.com/repository/docker/dclong/jupyterhub-ts and you can start a container using the command below.

docker run -it \
    --name jupyterhub-ts \
    --log-opt max-size=50m \
    -p 8000:8000 \
    -e DOCKER_USER=`id -un` \
    -e DOCKER_USER_ID=`id -u` \
    -e DOCKER_PASSWORD=`id -un` \
    -e DOCKER_GROUP_ID=`id -g` \
    -e DOCKER_ADMIN_USER=`id -un` \
    -v `pwd`:/workdir \
    -v `dirname $HOME`:/home_host \
    dclong/jupyterhub-ts

@dclong I downloaded your docker container and ran it. However, there was no error while I executed the container with following code blocks:

let x = 3
x
function* fib(){
    yield 1;
    yield 2;
    let x1 = 1; 
    let x2 = 2;
    while(true){
        let x = x1 + x2;
        x1 = x2;
        x2 = x;
        yield x;
    }
}
let gen = fib();
gen.next();
gen.next();

The results are shown here:
image

Here, I pasted the tsconfig.json that I used, which contains CompilerOptions that you mentioned previously:

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "nodejs",
    "esModuleInterop": true
  }
}

@nearbydelta Thank you so much! I've just tried again and it indeed works well. It must be due to the tsconfig.json file that I used. Sorry that I'm very newbie to TypeScript.

@nearbydelta I think the issue I encountered was actually due to Docker on Mac. The same Docker image works on Linux (with the latest version of Docker) but not on Mac (with the latest version of Docker). Anyway, it's not an issue from the iTypeScript kernel and I'll submit an issue to Docker for Mac later.