16
votes

I try to build project with Angular CLI ng build --prod and I get this error:

ERROR in TypeError: Cannot read property 'kind' of undefined

if I build with not --prod I do not get any error

Full error:

ERROR in TypeError: Cannot read property 'kind' of undefined
    at isParameterPropertyDeclaration (node_modules/typescript/lib/typescript.js:13445:88)
    at Object.filter (node_modules/typescript/lib/typescript.js:469:31)
    at transformClassMembers (node_modules/typescript/lib/typescript.js:70813:20)
    at createClassDeclarationHeadWithoutDecorators (node_modules/typescript/lib/typescript.js:70665:110)
    at visitClassDeclaration (node_modules/typescript/lib/typescript.js:70584:19)
    at visitTypeScript (node_modules/typescript/lib/typescript.js:70432:28)
    at visitorWorker (node_modules/typescript/lib/typescript.js:70227:24)
    at sourceElementVisitorWorker (node_modules/typescript/lib/typescript.js:70252:28)
    at saveStateAndInvoke (node_modules/typescript/lib/typescript.js:70165:27)
    at sourceElementVisitor (node_modules/typescript/lib/typescript.js:70237:20)
    at visitNodes (node_modules/typescript/lib/typescript.js:67751:48)
    at Object.visitLexicalEnvironment (node_modules/typescript/lib/typescript.js:67784:22)
    at visitSourceFile (node_modules/typescript/lib/typescript.js:70521:53)
    at saveStateAndInvoke (node_modules/typescript/lib/typescript.js:70165:27)
    at transformSourceFile (node_modules/typescript/lib/typescript.js:70147:27)
    at transformSourceFileOrBundle (node_modules/typescript/lib/typescript.js:70127:20)

Angular version:

Angular CLI: 8.3.3
Node: 12.9.0
OS: darwin x64
Angular: 9.0.0-next.5
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.900.0-next.3
@angular-devkit/build-angular      0.900.0-next.3
@angular-devkit/build-optimizer    0.900.0-next.3
@angular-devkit/build-webpack      0.900.0-next.3
@angular-devkit/core               9.0.0-next.3
@angular-devkit/schematics         8.3.3
@angular/cdk                       8.1.4
@angular/cli                       8.3.3
@angular/http                      8.0.0-beta.10
@angular/material                  8.1.4
@angular/material-moment-adapter   8.1.4
@ngtools/webpack                   9.0.0-next.3
@schematics/angular                8.3.3
@schematics/update                 0.803.3
rxjs                               6.5.3
typescript                         3.6.3
webpack                            4.39.3

Thanks.

5
The comments reported on this issue may help you. - Narm
@Narm I saw this page but it doesn't help, tnx. - Yakir Tsuberi
Add some code snippet to know where is the kind property that is trying to access, It would be very helpful to give us a anwser to you. - Diego Bascans
@DiegoBascans I added full error. - Yakir Tsuberi
@YakirTsuberi I was informed by the Angular team that TypeScript 3.6.4 will be released ASAP to fix this issue. - LppEdd

5 Answers

12
votes

Keep in mind now TypeScript 3.6.4 is out. Still, it's ok to read below what wasn't really working.

TypeScript <= 3.6.3 presents this issue, Handle parentless nodes in isParameterPropertyDeclaration.

If you install 3.7 (dev or the new beta), it will compile fine.


Note: if you receive an ERROR on building, regarding the TS version, just disable it via tsconfig.
For that use disableTypeScriptVersionCheck

"angularCompilerOptions": {
  "disableTypeScriptVersionCheck": true
},
"compilerOptions": {
 ...

Follow the comment's chat if any other problem emerges.

3
votes

This problem occurs by so many cases, one of the major reasons is installed version of @angular/cli is different to globally installed version of @angular/cli Make sure that both are same version. In other cases you have to update the devkit.

Please have a look on these threads, you will get an idea:

  1. https://github.com/angular/angular-cli/issues/13172
  2. https://github.com/angular/angular-cli/issues/13861
2
votes

Although the question specifically states isParameterPropertyDeclaration as the source of the error, this question is the only one linked by Google when searching for the following very similar error:

ERROR in ./node_modules/some_library/...
Module build failed (from ./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js):
TypeError: Cannot read property 'kind' of undefined

Since I couldn't find any good answer for the error above, I'm posting it here for reference.

If you're using a library affected by this error, you should upgrade your @angular/cli version to 8 or disable optimization in production mode (to disable optimization, change projects.your_project_name.architect.build.configurations.production.optimization from true to false).

If you're a library owner trying to fully support versions 6 and 7 of Angular, in the tsconfig.json of your library, set compilerOptions.emitDecoratorMetadata to true and recompile. Since now you're exporting all metadata from the decorators, Angular will do .kind of the exported metadata, fixing the problem where it was undefined.

2
votes

I ran in to this when I was using ng-recaptcha v6.0.2 with angular v6.2.2

For me, the fix was to set buildOptimizer to false in angular.json

"configurations": {
    "development": {
        "buildOptimizer": false
    }
}
0
votes

I got the same issue and solved it by updating my typescript dependency to the latest stable version.

In my case, I had version 3.7 and I fixed the issue by upgrading to 3.8.