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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'flags' of undefined #35021

Closed
charescape opened this issue Nov 10, 2019 · 31 comments · Fixed by #36111
Closed

TypeError: Cannot read property 'flags' of undefined #35021

charescape opened this issue Nov 10, 2019 · 31 comments · Fixed by #36111
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@charescape
Copy link

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:

@bugtype
Copy link

bugtype commented Nov 10, 2019

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?

@nmain
Copy link

nmain commented Nov 11, 2019

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 typescript@3.7.2

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

Presumably the issue depends on Typescript's js support.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Nov 12, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.8.0 milestone Nov 12, 2019
@sandersn
Copy link
Member

sandersn commented Dec 4, 2019

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:

@ZumelzuR
Copy link

ZumelzuR commented Feb 10, 2020

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)

@ErVishalM
Copy link

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.

@isipro
Copy link

isipro commented May 8, 2020

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!

@JoshuvaGeorge03
Copy link

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?

@SourabhJha
Copy link

SourabhJha commented May 8, 2020

Same here ,just tried

image

image

Please help

@isipro
Copy link

isipro commented May 8, 2020

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

@neon096
Copy link

neon096 commented May 8, 2020

I'm having same issues on 9.1.4

@reidsci
Copy link

reidsci commented May 8, 2020

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

@shikhasreekumar99
Copy link

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\typescript\lib\typescript.js:36513:37)
at checkAliasSymbol (C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:64502:26)
at checkImportBinding (C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:64534:13)
at checkImportDeclaration (C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:64552:29)
at checkSourceElementWorker (C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:64961:28)
at checkSourceElement (C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:64800:17)
at Object.forEach (C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:317:30)
at checkSourceFileWorker (C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:65123:20)
at checkSourceFile (C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:65091:13)
at getDiagnosticsWorker (C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:65179:17)
at Object.getDiagnostics (C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:65165:24)
at C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:98703:85
at runWithCancellationToken (C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:98665:24)
at getBindAndCheckDiagnosticsForFileNoCache (C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:98691:20)
at getAndCacheDiagnostics (C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:98956:26)
at getBindAndCheckDiagnosticsForFile (C:\Users\user-pc\Angularwithspringboot\node_modules\typescript\lib\typescript.js:98688:20)
2m

@isipro
Copy link

isipro commented May 8, 2020

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

angular/angular#37002

@Saxon-Liu
Copy link

I have the same problem, It worked yesterday。
I use ng 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\typescript\lib\typescript.js:36513:37)
at checkAliasSymbol (e:\mission\js\task6\node_modules\typescript\lib\typescript.js:64502:26)
at checkImportBinding (e:\mission\js\task6\node_modules\typescript\lib\typescript.js:64534:13)
at checkImportDeclaration (e:\mission\js\task6\node_modules\typescript\lib\typescript.js:64552:29)
at checkSourceElementWorker (e:\mission\js\task6\node_modules\typescript\lib\typescript.js:64961:28)
at checkSourceElement (e:\mission\js\task6\node_modules\typescript\lib\typescript.js:64800:17)
at Object.forEach (e:\mission\js\task6\node_modules\typescript\lib\typescript.js:317:30)
at checkSourceFileWorker (e:\mission\js\task6\node_modules\typescript\lib\typescript.js:65123:20)
at checkSourceFile (e:\mission\js\task6\node_modules\typescript\lib\typescript.js:65091:13)
at getDiagnosticsWorker (e:\mission\js\task6\node_modules\typescript\lib\typescript.js:65179:17)
at Object.getDiagnostics (e:\mission\js\task6\node_modules\typescript\lib\typescript.js:65165:24)
at e:\mission\js\task6\node_modules\typescript\lib\typescript.js:98703:85
at runWithCancellationToken (e:\mission\js\task6\node_modules\typescript\lib\typescript.js:98665:24)
at getBindAndCheckDiagnosticsForFileNoCache (e:\mission\js\task6\node_modules\typescript\lib\typescript.js:98691:20)
at getAndCacheDiagnostics (e:\mission\js\task6\node_modules\typescript\lib\typescript.js:98956:26)
at getBindAndCheckDiagnosticsForFile (e:\mission\js\task6\node_modules\typescript\lib\typescript.js:98688:20)

somebody can help me?

@shikhasreekumar99
Copy link

solution :

  1. npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4

  2. npm install

  3. ng serve

@boukhemis11
Copy link

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

npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4

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

@JoshuvaGeorge03
Copy link

JoshuvaGeorge03 commented May 8, 2020

Do delete node_modules and delete package-lock.json

and run

npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4 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)

@imabdullah
Copy link

solution :

  1. npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4
  2. npm install
  3. ng serve

this worked for me. Thanks

@Saxon-Liu
Copy link

solution :

  1. npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4
  2. npm install
  3. ng serve

it's worked. thanks

@ghost
Copy link

ghost commented May 8, 2020

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

@tigerjherold
Copy link

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

npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4

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.

@FerreirasDenise
Copy link

solution :

  1. npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4
  2. npm install
  3. ng serve

This worked for me.
Thanks

@ghost
Copy link

ghost commented May 8, 2020

solution :

  1. npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4
  2. npm install
  3. ng serve

This worked for me.
Thanks

this is only downgrade, not fix

@ErVishalM
Copy link

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

@UmarGit
Copy link

UmarGit commented May 8, 2020

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/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4

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

@Proposito
Copy link

solution :

  1. npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4
  2. npm install
  3. ng serve

its worked for me!
Thanks

@nojvek
Copy link
Contributor

nojvek commented May 20, 2020

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

@exomc
Copy link

exomc commented Jul 14, 2020

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"
}

@knaos
Copy link

knaos commented Sep 10, 2020

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

@sijakret
Copy link

sijakret commented Nov 23, 2020

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 typescript@3.8.2 (simple npm install) and then upgrading to typescript@3.9.2 (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!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.