Typescript: TypeError: Cannot read property 'flags' of undefined

Created on 10 Nov 2019  Β·  31Comments  Β·  Source: microsoft/TypeScript


TypeScript Version: 3.7.2

How to reproduce

  • (Step 1) Create file test.js
(function () {
  var obj = {};
  /**
   * test test
   * @constructor
   * @remind remind
   * @param { Object } options param
   * @example
   * ```javascript
   * var editor = new UE.Editor();
   * editor.execCommand('blod');
   * ```
   * @see TEST.Config
   */
  var a = obj.a = function (options) {
    console.log(this)
  };
})();
  • (Step 2) Create file tsconfig.json
{
  "compilerOptions": {
    "outDir": "./built",
    "allowJs": true,
    "newLine": "lf",
    "target": "es5"
  },
  "files": [
    "test.js"
  ]
}
  • (Step 3) Open git bash, run command tsc

Expected behavior:
no errors

Actual behavior:

$ tsc
C:\Users\talen\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:78566
                throw e;
                ^

TypeError: Cannot read property 'flags' of undefined
    at getFlowTypeOfReference (C:\Users\talen\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:42017:80)
    at tryGetThisTypeAt (C:\Users\talen\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:43171:28)
    at checkThisExpression (C:\Users\talen\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:43135:24)
    at checkExpressionWorker (C:\Users\talen\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:48624:28)
    at checkExpression (C:\Users\talen\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:48578:38)
    at checkExpressionWithContextualType (C:\Users\talen\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:48319:24)
    at getSignatureApplicabilityError (C:\Users\talen\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:45667:35)
    at chooseOverload (C:\Users\talen\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:46035:25)
    at resolveCall (C:\Users\talen\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:45938:26)
    at resolveCallExpression (C:\Users\talen\AppData\Roaming\npm\node_modules\typescript\lib\tsc.js:46256:20)

Playground Link:

Related Issues:

Bug Fix Available

Most helpful comment

solution :
1) npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected]

2) npm install

3) ng serve

All 31 comments

I think it's work well. what version of tsc are you using?
I have a question. why did you test the extension with .js?

I think it's work well. what version of tsc are you using?

I was able to reproduce the same issue trivially by following the exact steps given using [email protected]

I have a question. why did you test the extension with .js?

Presumably the issue depends on Typescript's js support.

No, it's more likely that the binder doesn't recognise this construction as a class and doesn't mark it with the Class flag. When that flag is missing, the code in the checker that adds thisType doesn't run, and subsequent code (like this) will crash.

It's probably related to syntactically locating @constructor on b or a in the binder in order to mark the anonymous function as a class.
I fixed a number of similar bugs for 3.7:

I'm using angular 5 and ionic v3. For me work these changes:
"@types/node": "^9.6.55",
"typescript": "3.7.4",
"@ionic/app-scripts": "3.2.3",`

Be sure that not use
"@angular-devkit/build-angular": "^0.803.7",
"@angular/cli": "^1.5.5",
that dependencies.

Be sure to remove your node_modules and do npm cache clean -f, then npm i (maybe will be good also remove your package-lock.json)

Hi,
I'm getting the error
**ERROR in TypeError: Cannot read property 'flags' of undefined**
When i updated to latest angular-cli packages
previous version

"@angular/animations": "^9.1.4",
"@angular/common": "^9.1.4",
"@angular/compiler": "^9.1.4",
"@angular/core": "^9.1.4",
"@angular/forms": "^9.1.4",
"@angular/platform-browser": "^9.1.4",
"@angular/platform-browser-dynamic": "^9.1.4",
"@angular/router": "^9.1.4",

current updated to latest which is

"@angular/animations": "^9.1.5",
"@angular/common": "^9.1.5",
"@angular/compiler": "^9.1.5",
"@angular/core": "^9.1.5",
"@angular/forms": "^9.1.5",
"@angular/platform-browser": "^9.1.5",
"@angular/platform-browser-dynamic": "^9.1.5",
"@angular/router": "^9.1.5",

Can somebody help me please.

Same here.
Just added a new 9.1.4 Angular project and serve gives the error
ERROR in TypeError: Cannot read property 'flags' of undefined

Package Version

@angular-devkit/architect 0.901.4
@angular-devkit/build-angular 0.901.4
@angular-devkit/build-optimizer 0.901.4
@angular-devkit/build-webpack 0.901.4
@angular-devkit/core 9.1.4
@angular-devkit/schematics 9.1.4
@angular/cli 9.1.4
@ngtools/webpack 9.1.4
@schematics/angular 9.1.4
@schematics/update 0.901.4
rxjs 6.5.5
typescript 3.8.3
webpack 4.42.0

Thanks for your advise!

Same here, I am having this error too. after updating from angular 9.1.4 to 9.1.5

"@angular/animations": "^9.1.5", "@angular/common": "^9.1.5", "@angular/compiler": "^9.1.5", "@angular/core": "^9.1.5", "@angular/forms": "^9.1.5", "@angular/platform-browser": "^9.1.5", "@angular/platform-browser-dynamic": "^9.1.5", "@angular/router": "^9.1.5",

how to fix this issue?

Same here ,just tried

image

image

Please help

9.1.4
@JoshuvaGeorge03 DId it work on 9.1.4 ?

Can you compare the package.json?
Something else must have updated which broke it

I'm having same issues on 9.1.4

Same here. Created a new app just a few hours ago and got the same error set as others before in this thread.

Angular CLI: 9.1.4
Node: 12.4.0
OS: win32 x64

Angular: 9.1.5
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Ivy Workspace: Yes

Package Version

@angular-devkit/architect 0.901.4
@angular-devkit/build-angular 0.901.4
@angular-devkit/build-optimizer 0.901.4
@angular-devkit/build-webpack 0.901.4
@angular-devkit/core 9.1.4
@angular-devkit/schematics 9.1.4
@angular/cli 9.1.4
@ngtools/webpack 9.1.4
@schematics/angular 9.1.4
@schematics/update 0.901.4
rxjs 6.5.5
typescript 3.8.3
webpack 4.42.0

Please help...! Any solution for the latest update?????????
ERROR in TypeError: Cannot read property 'flags' of undefined
at resolveAlias (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:36513:37)
at checkAliasSymbol (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:64502:26)
at checkImportBinding (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:64534:13)
at checkImportDeclaration (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:64552:29)
at checkSourceElementWorker (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:64961:28)
at checkSourceElement (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:64800:17)
at Object.forEach (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:317:30)
at checkSourceFileWorker (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:65123:20)
at checkSourceFile (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:65091:13)
at getDiagnosticsWorker (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:65179:17)
at Object.getDiagnostics (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:65165:24)
at C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:98703:85
at runWithCancellationToken (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:98665:24)
at getBindAndCheckDiagnosticsForFileNoCache (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:98691:20)
at getAndCacheDiagnostics (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:98956:26)
at getBindAndCheckDiagnosticsForFile (C:\Users\user-pc\Angularwithspringboot\node_modules\typescriptlib\typescript.js:98688:20)
2m

BTW, this is a closed issue.
I have just reported it with Angular here (its just a brand new installation for me )

https://github.com/angular/angular/issues/37002

I have the same problem, It worked yesterday。
I useng new created a new project and ng serve --open

@angular-devkit/architect 0.901.4
@angular-devkit/core 9.1.4
@angular-devkit/schematics 9.1.4
@schematics/angular 9.1.4
@schematics/update 0.901.4
rxjs 6.5.4
typescript 3.8.3

ERROR in TypeError: Cannot read property 'flags' of undefined
at resolveAlias (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:36513:37)
at checkAliasSymbol (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:64502:26)
at checkImportBinding (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:64534:13)
at checkImportDeclaration (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:64552:29)
at checkSourceElementWorker (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:64961:28)
at checkSourceElement (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:64800:17)
at Object.forEach (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:317:30)
at checkSourceFileWorker (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:65123:20)
at checkSourceFile (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:65091:13)
at getDiagnosticsWorker (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:65179:17)
at Object.getDiagnostics (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:65165:24)
at e:\mission\js\task6\node_modules\typescriptlib\typescript.js:98703:85
at runWithCancellationToken (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:98665:24)
at getBindAndCheckDiagnosticsForFileNoCache (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:98691:20)
at getAndCacheDiagnostics (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:98956:26)
at getBindAndCheckDiagnosticsForFile (e:\mission\js\task6\node_modules\typescriptlib\typescript.js:98688:20)

somebody can help me?

solution :
1) npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected]

2) npm install

3) ng serve

Something is broken in Angular 9.1.5 - if you run the following it should work:

npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected]

ng build
Just spent about 4-5 hours trying to fix it myself...

The issue seems to stem from using Angular CLI 9.1.4 with Angular 9.1.5 (most likely the compiler

You'll see the issue when you do

ng --version
if you get:

Angular CLI: 9.1.4
Node: 12.16.3
OS: win32 x64

Angular: 9.1.5
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Then you will need to follow the npm installs i listed above

Do delete node_modules and delete package-lock.json

and run

npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] ng build

and do ng serve.

it worked for me. check this stack overflow (https://stackoverflow.com/questions/61670882/error-in-typeerror-cannot-read-property-flags-of-undefined/61671596#61671596)

solution :

  1. npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected]
  2. npm install
  3. ng serve

this worked for me. Thanks

solution :

  1. npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected]
  2. npm install
  3. ng serve

it's worked. thanks

in addition, I had to execute a separate npm install to install the remaining modules, and only then a ng serve.

Something is broken in Angular 9.1.5 - if you run the following it should work:

npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected]

ng build
Just spent about 4-5 hours trying to fix it myself...

The issue seems to stem from using Angular CLI 9.1.4 with Angular 9.1.5 (most likely the compiler

You'll see the issue when you do

ng --version
if you get:

Angular CLI: 9.1.4
Node: 12.16.3
OS: win32 x64

Angular: 9.1.5
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Then you will need to follow the npm installs i listed above

This works for me. Thanks.

solution :

  1. npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected]
  2. npm install
  3. ng serve

This worked for me.
Thanks

solution :

  1. npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected]
  2. npm install
  3. ng serve

This worked for me.
Thanks

this is only downgrade, not fix

Hi @nikitanewmsk Thank you so much for immediate reply. But it is I'd done waiting for fix now. :)

Hello everyone , My problem is solved by downgrade which is probably not a fix at all but it works ! @shikhasreekumar99 : thank you πŸ‘

Step 1 : πŸ‘

Permanently delete your node modules.

Step 2 : πŸ‘

RUN THIS COMMAND ON YOUR CONSOLE
npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected]

Step 3 : πŸ’―

CONGRATULATIONS YOU SUCCESSFULLY DOWNGRADED THE DEPENDENCIES AND THE TYPEERROR IS RESOLVED SUCCESSFULLY
Now you may try these !
ng serve --open ng build .............etc

SCREEN SHOT OF SUCCESFULL NG SERVE

Capture

solution :

  1. npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected]
  2. npm install
  3. ng serve

its worked for me!
Thanks

I'm getting same error while tsc tries to compile highcharts.js

using tsc 3.8.3 with node 10.

Interestingly babel doesn't fail, but tsc does.

Well the error doesn't tell me which line is faulty, so I'm going down the rabbit hole to debug this out in tsc. Will get back with offending line.

Okay debugging through tsc at 1am in the morning isn't being very helpful. The node positions point me to this area

    /**
     * Override the basic data label alignment by adjusting for the position of the column
     */
    seriesTypes.column.prototype.alignDataLabel = function(point, dataLabel, options, alignTo, isNew) {
      var chart = this.chart,
        inverted = chart.inverted,
        dlBox = point.dlBox || point.shapeArgs, // data label box for alignment
        below = point.below || (point.plotY > pick(this.translatedThreshold, chart.plotSizeY)),
        inside = pick(options.inside, !!this.options.stacking); // draw it inside the box?

Is there a way to tell tsc not to parse jsdoc types in comments in js files when in transpile only mode. It's really surprising that transpileOnly makes tsc error out.

Here's the full file if tsc team wants to investigate. I will keep on digging deeper.

highcharts.src.es5.js.zip

Same error angular 10. Tried downgrading to 9.1.4, no difference, nothing works

"dependencies": {
"@angular/animations": "^10.0.3",
"@angular/common": "^10.0.3",
"@angular/compiler": "^10.0.3",
"@angular/core": "^10.0.3",
"@angular/forms": "^10.0.3",
"@angular/language-service": "^10.0.3",
"@angular/platform-browser": "^10.0.3",
"@angular/platform-browser-dynamic": "^10.0.3",
"@angular/router": "^10.0.3",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.3"
},
"devDependencies": {
"@angular-builders/custom-webpack": "^9.2.0",
"@angular-devkit/build-angular": "^0.1000.2",
"@angular/cli": "^10.0.2",
"@angular/compiler-cli": "^10.0.3",
"@types/jasmine": "~3.5.11",
"@types/jasminewd2": "~2.0.8",
"@types/node": "^14.0.23",
"buffer": "^5.6.0",
"child_process": "^1.0.2",
"codelyzer": "^6.0.0",
"eslint": "^7.4.0",
"fs": "0.0.1-security",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~5.0.2",
"karma": "~5.1.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.3",
"karma-jasmine": "~3.3.1",
"karma-jasmine-html-reporter": "^1.5.4",
"net": "^1.0.2",
"process": "^0.11.10",
"protractor": "~7.0.0",
"tls": "0.0.1",
"ts-node": "~8.10.2",
"tslint": "~6.1.2",
"typescript": "^3.9.6"
}

Are you using Yarn? I am getting this error when using yarn

still an issue.
facing the same with angular 10

"@angular/animations": "^10.1.0",
"@angular/common": "^10.1.0",
"@angular/compiler": "^10.1.0",
"@angular/core": "^10.1.0",
"@angular/forms": "^10.1.0",
"@angular/platform-browser": "^10.1.0",
"@angular/platform-browser-dynamic": "^10.1.0",
"@angular/router": "^10.1.0",
"@angular-devkit/build-angular": "~0.1001.3",
"@angular/cli": "~10.1.3",
"@angular/compiler-cli": "^10.1.0",
"@angular/language-service": "^10.1.0",

Edit:
this is really giving me headaches.
i found this:

  • downgrading to [email protected] (simple npm install) and then upgrading to [email protected] (which is the minimum required version for the angular cli in the project) makes this work, at least temporarily.
  • this happens on the repo on MacOS (10.15.6) as well as Windows 10!
Was this page helpful?
0 / 5 - 0 ratings