TypeError: Cannot read property 'kind' of undefined at getAssignmentTargetKind
Asked Answered
D

15

36

This problem started to occur when updating my Angular 6 project to 7.x.

I opened an issue on the angular-cli github repo but they couldn't help.

So what I did is create a new project and add all components one by one to "hopefully" notice what caused the problem.

Unfortunately I couldn't identify the problem. Here's the log:

ERROR in : TypeError: Cannot read property 'kind' of undefined
at getAssignmentTargetKind (E:\McClient\node_modules\typescript\lib\typescript.js:10049:28)
at Object.isAssignmentTarget (E:\McClient\node_modules\typescript\lib\typescript.js:10092:16)
at checkObjectLiteral (E:\McClient\node_modules\typescript\lib\typescript.js:46107:45)
at checkExpressionWorker (E:\McClient\node_modules\typescript\lib\typescript.js:50748:28)
at checkExpression (E:\McClient\node_modules\typescript\lib\typescript.js:50696:42)
at checkExpressionWithContextualType (E:\McClient\node_modules\typescript\lib\typescript.js:50524:26)
at checkApplicableSignature (E:\McClient\node_modules\typescript\lib\typescript.js:47963:35)
at chooseOverload (E:\McClient\node_modules\typescript\lib\typescript.js:48281:26)
at resolveCall (E:\McClient\node_modules\typescript\lib\typescript.js:48231:26)
at resolveCallExpression (E:\McClient\node_modules\typescript\lib\typescript.js:48534:20)
at resolveSignature (E:\McClient\node_modules\typescript\lib\typescript.js:48800:28)
at getResolvedSignature (E:\McClient\node_modules\typescript\lib\typescript.js:48844:26)
at checkCallExpression (E:\McClient\node_modules\typescript\lib\typescript.js:48936:29)
at checkExpressionWorker (E:\McClient\node_modules\typescript\lib\typescript.js:50759:28)
at checkExpression (E:\McClient\node_modules\typescript\lib\typescript.js:50696:42)
at resolveDecorator (E:\McClient\node_modules\typescript\lib\typescript.js:48741:28)

Here's a link to the github issue with logs from a checkSourcefile function I was supposed to log:

https://github.com/angular/angular-cli/issues/13172

How can I track down and (hopefully) fix what's causing this?

Edit: My ng --version info

Angular CLI: 7.1.3
Node: 8.11.4
OS: win32 x64
Angular: 7.1.3
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.11.3
@angular-devkit/build-angular     0.11.3
@angular-devkit/build-optimizer   0.11.3
@angular-devkit/build-webpack     0.11.3
@angular-devkit/core              7.1.3
@angular-devkit/schematics        7.1.3
@angular/cdk                      7.1.1
@ngtools/webpack                  7.1.3
@schematics/angular               7.1.3
@schematics/update                0.11.3
rxjs                              6.3.3
typescript                        3.1.6
webpack                           4.23.1
Dupre answered 18/12, 2018 at 6:36 Comment(2)
Please ensure that you've followed all the steps shown here for migration - update.angular.io and then try to delete all your node_modules & reinstall them using npm installVandervelde
I tried this already - no luckDupre
C
17

I simply re-run

    ng serve

again and it worked!

Chip answered 12/2, 2019 at 7:23 Comment(3)
Well yes. But it's annoying to do that ~50 times a day. Still looking for an actual fixDupre
This solved for me too and just a note: Error started happening to me when i added custom javascript code to my Angular app (Typescript)Niece
This is answer is works. But couldn't found the actual root cause why this error occurred. In my case I am facing after every 1 or 2 hours while developing while ng serve is running.Gilgai
J
4

I struggled with the same problem, did some digging and found 2 major solutions:

  1. Installing '@types/history' package.
  2. Downgrading typescript to 3.1.6(since the bug wasn't occurring then).

See this GitHub issue here.

Janiecejanifer answered 27/2, 2019 at 7:43 Comment(0)
G
4

Run the application again using ng serve and it fixed the issue for me. It happened when I pulled code from a branch to my existing running branch which was running via ng serve.

Gladisgladney answered 2/4, 2019 at 12:53 Comment(0)
C
4

Disclaimer: this is not a good "fix", but it will get the job done if you're in a pinch. This is an issue related to the Angular devkit and build optimizer and has to do with version mismatches.

I ran into this problem and found a workaround in the case that upgrading Angular or other NPM packages isn't the ideal option to get things working immediately. This comment on Github pointed me in the right direction. In the file ./node_modules/@angular-devkit/build-optimizer/src/transforms/scrub-file.js in your project directory, there is a function called isAngularDecoratorMetadataExpression somewhere around line 237 (depending on the version you have). It has the following code toward the bottom of the function:

// Check second array entry for __metadata call.
if (decorateArray.elements[1].kind !== ts.SyntaxKind.CallExpression) {
  return false;
}

If you add this code just above those lines and save the file, it will bypass the problem:

// Workaround for missing metadata.
if(!decorateArray.elements[1]) {
  return false;
}

And after you have done that, run this command to try building your project again:

node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --prod --build-optimizer
Cerell answered 11/6, 2020 at 22:58 Comment(2)
This is just workaround. Have u found solution for this?Edlin
This is a good enough fix for me. Project is in the toilet and I could care less to fix this being that the project is in NG6 and we have a replacement in the works using 11.Leix
S
2

I also had this problem. I solved it by updating my local @angular/cli to the same version as the @anguluar/cli version in my project .

Suellensuelo answered 8/4, 2019 at 10:48 Comment(0)
L
2

It solved from version

npm i @angular-devkit/[email protected] -s

check this https://www.npmjs.com/package/@angular-devkit/build-angular

Lili answered 28/1, 2020 at 13:25 Comment(0)
D
2
  • I was having issue with while migrating ionic application from V4 to V5.
  • This is my error log image.

enter image description here

  • It was fixed with the below solution.

https://github.com/ckeditor/ckeditor4-angular/issues/78#issuecomment-565803253

Dorsey answered 3/3, 2020 at 6:42 Comment(0)
T
2

In my case downgrading @angular-builders/custom-webpack from version 10.0.1 to version 10.0.0 in package.json worked.

Temporary answered 30/11, 2020 at 11:8 Comment(0)
S
2

I ran into this issue, and it turns out that @angular-devkit/build-angular was in devDependencies when I was trying to build for prod – so moving that to dependencies solved the problem.

Sepulchre answered 26/6, 2021 at 22:4 Comment(0)
D
1

I had the same issue when I tried to run the angular application in production mode

I tried this npm i @angular-devkit/build-angular and it helped

Downhill answered 13/7, 2020 at 7:25 Comment(0)
E
1

Updating the typescript devDependency from 3.9.0 to 4.0.3 and running ng g c [directory-name] --skip-import

Earwax answered 4/10, 2020 at 18:47 Comment(1)
The above solution works perfectly when the error occurred is "Option "entryComponent" is deprecated: Since version 9.0.0 with Ivy, entryComponents is no longer necessary. cannot read property "kind" of undefined"Earwax
D
0

In my case the problem was that I had abstract classes with @Injectable, removing it solved the issue.

Hopes it helps

Deon answered 1/2, 2020 at 18:22 Comment(0)
S
0

I got this error while building application, i modified build configurations in angular.json it worked!!

{
  ...
  "configurations": {
    "production": {
      budgets: [
        "initial": true,
        minimum: 5mb,
        maximum: 8mb
      ],
      "common-chunk": true
      "vendor-chunk": true
    }
  }
}
Sassafras answered 7/8, 2020 at 3:18 Comment(0)
L
0

For me, the serve command was working fine, but the build command gave the error.

The error was, since we were using a custom builder '@angular-builders/custom-webpack'. The version of this package caused the issue.

Once I installed the correct version of this package as per our angular version, the issue was solved.

Lotz answered 7/1, 2021 at 15:9 Comment(0)
H
0

Well I finally got to solve this by adding --poll 1000 when running ng serve:

ng serve --poll 1000

Heyduck answered 23/8, 2021 at 20:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.