Typescript: TS 3.9 error when calling "tsc --watch" (TypeError: Cannot read property 'flags' of undefined)

Created on 13 May 2020  ·  3Comments  ·  Source: microsoft/TypeScript

TypeScript Version: 3.9.2

Hi, I updated my project to just released TS 3.9 and it compiles but gives error when I run it in watch mode.

I managed to find that the issue was that I had "compilerOptions.module=none" I changed it to "commonjs" and it compiles now so it's good workaround. But still, worth fixing. I don't use modules in my code I just have some type definitions manually copied from definitely typed that is causing the problem.

Here is project so you can reproduce it:
tsc_3_9_watch_bug.zip

I tested it on 3.8.3 and it works, on 3.9.2 and "next" there is an error. Here's my console transcript:

C:\Users\Mariusz\Documents\_kodzenie\typescript\tsc_3_9_watch_bug
>
PS>tsc

C:\Users\Mariusz\Documents\_kodzenie\typescript\tsc_3_9_watch_bug
>
PS>tsc --watch
[21:59:29] Starting compilation in watch mode...

C:\Users\Mariusz\AppData\Local\Yarn\Data\global\node_modules\typescript\lib\tsc.js:10245
        return !!(module.flags & 1024);
                         ^

TypeError: Cannot read property 'flags' of undefined
    at Object.isGlobalScopeAugmentation (C:\Users\Mariusz\AppData\Local\Yarn\Data\global\node_modules\typescript\lib\tsc.js:10245:26)
    at C:\Users\Mariusz\AppData\Local\Yarn\Data\global\node_modules\typescript\lib\tsc.js:84773:96
    at Object.some (C:\Users\Mariusz\AppData\Local\Yarn\Data\global\node_modules\typescript\lib\tsc.js:587:25)
    at containsGlobalScopeAugmentation (C:\Users\Mariusz\AppData\Local\Yarn\Data\global\node_modules\typescript\lib\tsc.js:84773:23)
    at isFileAffectingGlobalScope (C:\Users\Mariusz\AppData\Local\Yarn\Data\global\node_modules\typescript\lib\tsc.js:84776:20)
    at Object.create (C:\Users\Mariusz\AppData\Local\Yarn\Data\global\node_modules\typescript\lib\tsc.js:84597:139)
    at createBuilderProgramState (C:\Users\Mariusz\AppData\Local\Yarn\Data\global\node_modules\typescript\lib\tsc.js:84843:37)
    at Object.createBuilderProgram (C:\Users\Mariusz\AppData\Local\Yarn\Data\global\node_modules\typescript\lib\tsc.js:85346:21)
    at createEmitAndSemanticDiagnosticsBuilderProgram (C:\Users\Mariusz\AppData\Local\Yarn\Data\global\node_modules\typescript\lib\tsc.js:85580:19)
    at host.createProgram (C:\Users\Mariusz\AppData\Local\Yarn\Data\global\node_modules\typescript\lib\tsc.js:89124:20)
C:\Users\Mariusz\Documents\_kodzenie\typescript\tsc_3_9_watch_bug
>
PS>npx [email protected] --watch
[21:59:44] Starting compilation in watch mode...

[21:59:46] Found 0 errors. Watching for file changes.

^CTerminate batch job (Y/N)? Y
PS>TerminatingError(): "The pipeline has been stopped."
>> TerminatingError(): "The pipeline has been stopped."
C:\Users\Mariusz\Documents\_kodzenie\typescript\tsc_3_9_watch_bug
>
PS>npx [email protected] --watch
[22:00:07] Starting compilation in watch mode...

Cannot read property 'flags' of undefined
^CTerminate batch job (Y/N)? Y
PS>TerminatingError(): "The pipeline has been stopped."
>> TerminatingError(): "The pipeline has been stopped."
C:\Users\Mariusz\Documents\_kodzenie\typescript\tsc_3_9_watch_bug
>
PS>npx typescript@next --watch
[22:00:24] Starting compilation in watch mode...

Cannot read property 'flags' of undefined
^CTerminate batch job (Y/N)? Y
PS>TerminatingError(): "The pipeline has been stopped."
>> TerminatingError(): "The pipeline has been stopped."
C:\Users\Mariusz\Documents\_kodzenie\typescript\tsc_3_9_watch_bug
>

when you change module "none" to "commonjs" and run tsc --watch it works fine.

Bug Fixed

Most helpful comment

I also reported this yesterday #38545

All 3 comments

I also reported this yesterday #38545

Fixed or not fixed in TypeScript 3.9.6?

I think this is fixed in TypeScript 4.0 RC. Can you all verify?

npm install --save-dev typescript@rc

yarn add -D typescript@rc
Was this page helpful?
0 / 5 - 0 ratings