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
Same issue here with @angular/cli 1.5.0
Works without aot.
Same here, except that it does not work either without AOT. Without AOT, it takes over 140 seconds to build, and throws the following error when actually running:
main.eed5882cd957c35b82be.bundle.js:1 Uncaught Error: Unexpected value 'e' imported by the module 'e'. Please add a @NgModule annotation.
at c (main.eed5882cd957c35b82be.bundle.js:1)
at main.eed5882cd957c35b82be.bundle.js:1
at Array.forEach (<anonymous>)
at e.getNgModuleMetadata (main.eed5882cd957c35b82be.bundle.js:1)
at e._loadModules (main.eed5882cd957c35b82be.bundle.js:1)
at e._compileModuleAndComponents (main.eed5882cd957c35b82be.bundle.js:1)
at e.compileModuleAsync (main.eed5882cd957c35b82be.bundle.js:1)
at e.compileModuleAsync (main.eed5882cd957c35b82be.bundle.js:1)
at e.bootstrapModule (main.eed5882cd957c35b82be.bundle.js:1)
at Object.cDNt (main.eed5882cd957c35b82be.bundle.js:1)
@Axure it builds successfully for me with ng build --prod --aot=false
I seem to have found out the problem. The problematic code there is:
switch (node.kind) {
case 229 /* ClassDeclaration */:
// classes are valid targets
return true;
case 149 /* PropertyDeclaration */:
// property declarations are valid if their parent is a class declaration.
return node.parent.kind === 229 /* ClassDeclaration */;
It seems to fail to find the parent of the node when the node is a property declaration. I suddenly realized that it was the @select decorator from angular-redux, and I'm pretty sure the decorator is valid. So I tried adding the following line to bypass the check.
if (!node.parent) return true;
And it turns out to be working.
Facing this issue with Angular Cli 1.5.2 Works fine with 1.5.0
Angular Version: 1.5.2
@arsyed04 - Yup was getting error with Angular Cli 1.5.2 but worked fine when rolled back to 1.5.0 Thanks.
Not sure if it's really needed but my TypeScript version was 2.6.1
My typescript version is also same "typescript": "^2.6.1"
same error and my version is "typescript": "~2.4.2"
Same error with cli 1.5.2. Downgraded to 1.5.0 and it worked.
@angular/cli: 1.5.2 @angular/xxxx: 5.0.2 typescript: 2.4.2
ERROR in Error: TypeError: Cannot read property 'kind' of undefined
at nodeCanBeDecorated (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:7805:35)
at nodeIsDecorated (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:7825:16)
at Object.nodeOrChildIsDecorated (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:7829:16)
at isDecoratedClassElement (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:51668:23)
at isInstanceDecoratedClassElement (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:51659:20)
at Object.filter (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:1652:25)
at getDecoratedClassElements (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:51641:23)
at generateClassElementDecorationExpressions (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:51815:27)
at addClassElementDecorationStatements (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:51804:44)
at visitClassDeclaration (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:51131:13)
at visitTypeScript (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:50972:28)
at visitorWorker (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:50785:24)
at sourceElementVisitorWorker (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:50817:28)
at saveStateAndInvoke (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:50738:27)
at sourceElementVisitor (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:50799:20)
at visitNodes (/Users/cchen6/Desktop/Codes/barter/angular-sell-contract-ui/node_modules/typescript/lib/typescript.js:49280:48)
Im having the same error since I use the md-bootstrap project.
Getting same error.
@angular/angular-cli 1.5.3 @angular/core 5.0.2 typescript 2.6.1
Running: ng build --prod --aot
Produces:
ERROR in Error: TypeError: Cannot read property 'kind' of undefined
at nodeCanBeDecorated (/path-to-site/node_modules/typescript/lib/typescript.js:8350:36)
at nodeIsDecorated (/path-to-site/node_modules/typescript/lib/typescript.js:8364:16)
at nodeOrChildIsDecorated (/path-to-site/node_modules/typescript/lib/typescript.js:8368:16)
at Object.forEach (/path-to-site/node_modules/typescript/lib/typescript.js:1521:30)
at Object.childIsDecorated (/path-to-site/node_modules/typescript/lib/typescript.js:8374:27)
at getClassFacts (/path-to-site/node_modules/typescript/lib/typescript.js:52945:20)
at visitClassDeclaration (/path-to-site/node_modules/typescript/lib/typescript.js:52970:25)
at visitTypeScript (/path-to-site/node_modules/typescript/lib/typescript.js:52828:28)
at visitorWorker (/path-to-site/node_modules/typescript/lib/typescript.js:52624:24)
at sourceElementVisitorWorker (/path-to-site/node_modules/typescript/lib/typescript.js:52653:28)
at saveStateAndInvoke (/path-to-site/node_modules/typescript/lib/typescript.js:52568:27)
at sourceElementVisitor (/path-to-site/node_modules/typescript/lib/typescript.js:52638:20)
at visitNodes (/path-to-site/node_modules/typescript/lib/typescript.js:50937:48)
at Object.visitLexicalEnvironment (/path-to-site/node_modules/typescript/lib/typescript.js:50970:22)
at visitSourceFile (/path-to-site/node_modules/typescript/lib/typescript.js:52915:53)
at saveStateAndInvoke (/path-to-site/node_modules/typescript/lib/typescript.js:52568:27)
Edit: I've also narrowed it down to a specific decorator I'm using throughout my app. Removing the instances of the @Throttle() decorator (from lodash-decorators) from my app "fixes" my issue.
Same error.
@angular/angular-cli 1.5.0 @angular/core 5.0.2 typescript 2.6.1
Running: ng build --aot
I confirm erro still here with last release 1.5.4 / 1.6.0-rc.0 :
Angular CLI: 1.6.0-rc.0
Node: 8.9.1
OS: win32 x64
Angular: 5.0.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.6.0-rc.0
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.21
@angular-devkit/schematics: 0.0.37
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.0-rc.0
@schematics/angular: 0.1.7
typescript: 2.4.2
webpack: 3.8.1
ps: I tried with ts 2.5.3 and with ng serve it works but with --aot or ng build it throw this error
@niveo please fix your links when click ??
https://github.com/Microsoft/TypeScript/issues/17384
In my case, the error was caused by arrow functions used as parameters of decorators.
IE : @someAnnotation(t=>!!t) someField; for example
To find them, use a Regexp search or add a console.log in the typescript.js file before re-compiling :
case 149 /* PropertyDeclaration */:
if (!node.parent) {
console.log("###### No Node parent on " + node.name.escapedText);
}
// property declarations are valid if their parent is a class declaration.
return node.parent.kind === 229 /* ClassDeclaration */;
Then it was easy to replace those with named function
function someFn(t) {
return !!t;
}
[...]
@someAnnotation(someFn) someField;
Huge THANK YOU! You are save my time :)
I'm having the same problem and found it's because of arrow functions in decorators, like:
@Type(() => Message)
When I change the above to:
function m() { return Message; }
@Type(m)
It compiles with AOT again =)
https://github.com/typestack/class-transformer/issues/108
@rmrevin
export function serializeType<T>(object: T) {
return function () { return object; }
}
export class CatalogItem {
id: string;
@Type(serializeType(CatalogCategory))
category?: CatalogCategory = null;
@Type(serializeType(PackingVariant))
packing: PackingVariant;
price: string = null;
}
Angular CLI: 1.5.4 Node: 8.9.1 OS: win32 x64 Angular: 5.0.3
I'm having an issue with a @Debounce decorator.
Using the above console.log() in typescript.ts I get ###### No Node parent on onWindowChange for case 151
export function Debounce(delay: number = 300): MethodDecorator {
return function (
_target: any,
_propertyKey: string,
descriptor: PropertyDescriptor
) {
let timeout: any = null;
const original = descriptor.value;
descriptor.value = function (...args: any[]) {
clearTimeout(timeout);
timeout = setTimeout(() => original.apply(this, args), delay);
};
return descriptor;
};
}
...
// inside component class ...
@HostListener('window:orientationChange', [])
@HostListener('window:resize', [])
@Debounce()
onWindowChange() { ... }
Replacing the decorator with the timeout code in onWindowChange() fixes the issue.
@Axure
I use @select decorator from angular-redux, locally i can run the app without any problems, however when i try to build it in prod i get the same error above. I don't want to edit the typescript.js file manually to bypass the check. any suggestions ???