AOT build error Cannot read property 'kind' of undefined
Bug Report or Feature Request (mark with an x)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
Angular CLI: 1.5.0 Node: 8.5.0 OS: darwin x64 Angular: 5.0.1 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router
@angular/cdk: 5.0.0-rc0 @angular/cli: 1.5.0 @angular/flex-layout: 2.0.0-beta.10-4905443 @angular/material: 5.0.0-rc0 @angular-devkit/build-optimizer: 0.0.32 @angular-devkit/core: 0.0.20 @angular-devkit/schematics: 0.0.35 @ngtools/json-schema: 1.1.0 @ngtools/webpack: 1.8.0 @schematics/angular: 0.1.2 typescript: 2.4.2 webpack-bundle-analyzer: 2.9.1 webpack: 3.8.1
Repro steps.
rm -rf node_modules/ yarn add @angular/cli@latest -D ng build --aot
The log given by the failure.
ERROR in Error: TypeError: Cannot read property 'kind' of undefined
at nodeCanBeDecorated (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:7805:35)
at nodeIsDecorated (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:7825:16)
at Object.nodeOrChildIsDecorated (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:7829:16)
at isDecoratedClassElement (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:51668:23)
at isInstanceDecoratedClassElement (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:51659:20)
at Object.filter (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:1652:25)
at getDecoratedClassElements (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:51641:23)
at generateClassElementDecorationExpressions (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:51815:27)
at addClassElementDecorationStatements (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:51804:44)
at visitClassDeclaration (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:51131:13)
at visitTypeScript (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:50972:28)
at visitorWorker (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:50785:24)
at sourceElementVisitorWorker (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:50817:28)
at saveStateAndInvoke (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:50738:27)
at sourceElementVisitor (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:50799:20)
at visitNodes (/Users/sam/Developer/ng-prime/node_modules/typescript/lib/typescript.js:49280:48)
Desired functionality.
AOT build should be successful
Mention any other details that might be useful.
The project built fine with AOT enabled with CLI v1.4.9
Also @angular/compiler-cli as of v5.1.2 seems to require typescript@>=2.4.2 <2.5.0. Cross-linked issue above where, quote:
If you 2.5 or 2.6 with ngc version 5.0.3 it will silently produce bad output in certain cases
Given that's the case, I don't think it's necessarily secure to upgrade to TS 2.7-ish. See also from https://github.com/angular/angular/issues/21157#issuecomment-353767980:
We have no idea if 2.7-dev is compatible or not. Typically every minor version of typescript changes the AST apis which break our compiler so we need to tweak things every time.
@filipesilva sorry to pressure, but is there any progress to report? For our teams, the CLI is currently frozen on v1.5.0.
I had the same issue. I could resolve it with installing dev version of angular/cli and typescript:
npm install @angular/cli@next npm install typescript@next
The underlying cause is a defect in TypeScript which is fixed in newer versions of TypeScript. The CLI in more recent versions uses more capability of the TypeScript transformation subsystem. This in turn exposed the TypeScript defect to CLI users. As newer versions of TypeScript are not yet officially supported by Angular, the CLI will need to add a workaround for the underlying Typescript defect. The CLI already has a workaround in place for a different decorator related defect and this should be able to be augmented to support handling the defect here as well.
After installing the angular/cli dev version, I get the following problems: Stackoverflow - Angular CLI - After refreshing in browser the browser try to load files from a wrong location
@Brocco @clydin I still get the issue in the 1.6.5 cli version, I undid a class-transformer workaround (show at the end of this comment) and I still get the same kind error:
ERROR in : TypeError: Cannot read property 'kind' of undefined
at nodeCanBeDecorated (/node_modules/typescript/lib/typescript.js:8376:36)
at nodeIsDecorated (/node_modules/typescript/lib/typescript.js:8396:16)
at nodeOrChildIsDecorated (/node_modules/typescript/lib/typescript.js:8400:16)
at Object.forEach (/node_modules/typescript/lib/typescript.js:1526:30)
at Object.childIsDecorated (/node_modules/typescript/lib/typescript.js:8406:27)
at getClassFacts (/node_modules/typescript/lib/typescript.js:53119:20)
at visitClassDeclaration (/node_modules/typescript/lib/typescript.js:53144:25)
at visitTypeScript (/node_modules/typescript/lib/typescript.js:53002:28)
at visitorWorker (/node_modules/typescript/lib/typescript.js:52798:24)
at sourceElementVisitorWorker (/node_modules/typescript/lib/typescript.js:52827:28)
at saveStateAndInvoke (/node_modules/typescript/lib/typescript.js:52742:27)
at sourceElementVisitor (/node_modules/typescript/lib/typescript.js:52812:20)
at visitNodes (/node_modules/typescript/lib/typescript.js:51104:48)
at Object.visitLexicalEnvironment (/node_modules/typescript/lib/typescript.js:51137:22)
at visitSourceFile (/node_modules/typescript/lib/typescript.js:53089:53)
at saveStateAndInvoke (/node_modules/typescript/lib/typescript.js:52742:27)
Typescript: 2.6.2 Angular: 5.2.1
Workaround used:
export function serializeType<T>(object: T) {
return function () { return object; };
}
...
@Type(serializeType(Participant))
public participants: Participant[] = [];
I am also seeing the same issue with angular-cli v1.6.5
@philjones88 where did you apply this workaround? Is it general fix?
@arsyed04 I applied it to any usages of @Type(() => MyType) from the class-transformer library I had in my application
Same issue with "@angular/cli": "^1.6.8"
issue with md-bootstrap is fixed with typescript 2.7.1
@morganster this issue is about --aot compilation
It still broken angular cli: 1.7.4 angular version: 5.2.10 typescript: 2.8.3 webpack: 3.11.0
it is not possible to build with: ng build --prod still breaks with: TypeError: Cannot read property 'kind' of undefined
@front-end-developer: TypeScript 2.8.x is not yet supported. Please install a version that matches the Angular compiler's peer dependency: https://github.com/angular/angular/blob/5.2.10/packages/compiler-cli/package.json#L18
Thanks for this, now I ran: npm install typescript@'>=2.4.2 <2.7'
it installed: "typescript": "^2.6.2"
when i run ng build --prod: because I saw errors about: Function calls are not supported in decorators but 'ɵmakeDecorator' was called in 'Component' 'Component' calls 'ɵmakeDecorator'
I changed it to: 2.7.0-rc that fixed it.
Then i run ng build --prod: Now it cries: ERROR in Cannot read property 'kind' of undefined searched all day to fix that error: but never found a solution has anybody ever found a solution this this error?
- anyone knows what version of node is recommended for Angular 5.2.10? my nvm lists has: 8.9.4, 8.9.0, 7.6.0 & 7.10.1
So this fix worked for me: I was using nvm (node version manager) and switching between node versions to find the solutions, you have to select the right version of node, I have 64bit version and node-sass was asking for 32bit version.
I had to do: npm rebuild node-sass but then after a build I had that error, during node-sass rebuild I noticed it was saying it could not find python 2.
So I ran the command from powershell as administrator: npm --add-python-to-path='true' --debug install --global windows-build-tools npm install --global node-gyp
then I switch to a 32 bit node version: nvm use 7.x.x 32
you can check your nvm version with the command: nvm list 7.6.0 (Currently using 32-bit executable)
So that fixed that, then I ran: npm rebuild node-sass
then tried to find a compatible typescript version that would not torment my production build: "typescript": "^2.6.2"
that fixed my issues.
so the only error I am seeing now is: Function calls are not supported in decorators but 'ɵmakeDecorator' was called in 'Component' 'Component' calls 'ɵmakeDecorator'
but this is manageable.
I had same problem today.
TypeError: Cannot read property 'kind' of undefined
(...)
...and I fix it just upgrading my Typescript for 2.6.2.
These steps worked for me: 1)Clear package.json with the importat packages for example I have delete my package and insert one by one here is my
{
"name": "test-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.0",
"@angular/cdk": "^6.4.2",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/flex-layout": "^6.0.0-beta.17",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/material": "^6.4.2",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"angular2-uuid": "^1.1.1",
"chartist": "^0.11.0",
"core-js": "^2.5.4",
"jquery": "^3.3.1",
"rxjs": "^6.0.0",
"rxjs-compat": "^6.2.2",
"webpack": "^4.16.3",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.7.0",
"@angular/cli": "^6.1.2",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"npm-install-webpack-plugin": "^4.0.5",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "^2.7.2",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5"
}
}
- delete package_locked.json
- delete node_modules folder
- npm install
- Then ng build --prod was successful.
The problem might be in the ^ of the packages. IN my case the problem was typescript version I had
"typescript": "^3.1.3", and npm installed version 3.2.2.
Changed to "typescript": "3.1.3", ran npm install and the problem got fixed.