So when got this trouble in Angular-CLI app.
Here is what happening:
ng serve
, ng serve --aot
produces no exceptions, everything works fine. Only running ng serve --prod
breaks while surfing the app.
ERROR TypeError: (void 0) is not a function
Was searching for answers, and found these dont's, so I have written 'public' before every property in app and checked if there was function calls in providers, but nothing changed.
Next I tried running it with --aot
flag and was working just fine, but still crashing while --prod
with same errors.
It crashes exactly while runnig login process which is:
- send http POST with login and password data
- if request resolves, dispatch ngRx-Store custom login event (simple flag)
- then router.navigateByUrl to another page
It is weird that I have similar processes everywhere, but it crashes in the exact place.
Can please someone provide me a little info abut where should I dig next? Cheers!
UPDATE: I was cutting off in code every single part of login process, and then building it with --prod
, and it turns out that MatDialog from @angular/material was producing the error. Login was triggered after MatDialog login component resolves with afterClosed() hook to its parent, and it produces exceptions somehow.
So parent, who was triggered pop-up was HeaderComponent, which contains method:
openLoginDialog(): void {
this.authService.login();
const dialogRef = this.dialog.open(LoginDialogComponent);
dialogRef.afterClosed().subscribe(result => {
if (result) {
this.authService.login();
}
});
}
And inside LoginDialogComponent was method which simply resolves:
login(login, password) {
this.authService.tryLogin(login, password).subscribe(data => {
this.dialogRef.close(true);
});
}
After I removed MatDialog in another words got rid of the only popup on project, the error disappeared. I have made another component with its own route for Login form, but still consider that removing whole working module beacause of build errors is not a solution.
my package.json:
"dependencies": {
"@angular/animations": "^5.0.2",
"@angular/cdk": "^5.0.0-rc.1",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/flex-layout": "^2.0.0-beta.10-4905443",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/material": "^5.0.0-rc.1",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/platform-server": "^5.0.0",
"@angular/router": "^5.0.0",
"@ngrx/store": "^5.0.0",
"@nguniversal/common": "^5.0.0-beta.5",
"@nguniversal/express-engine": "^5.0.0-beta.5",
"@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.5",
"core-js": "^2.4.1",
"hammerjs": "^2.0.8",
"ngrx-store-freeze": "^0.2.0",
"primeng": "^5.0.2",
"rxjs": "^5.5.2",
"tassign": "^1.0.0",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "^1.6.2",
"@angular/compiler-cli": "^5.0.0",
"@angular/language-service": "^5.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "~3.2.0",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-loader": "^2.3.7",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.4.2"
}
ng serve
orng build
won't throw the typo or kind of errors but when you dong serve --prod
orng build --prod
it will. – Spinose--prod
making this error. And there are no errors in terminal while building or serving, they fall only in browser. I am using the exact commandsng build --prod && ng serve --prod
– Acus--environment prod
--aot true
--output-hashing all
--sourcemaps false
--extract-css true
--named-chunks false
--build-optimizer true
If the error does not occur with those, it is very likely to be caused byuglify.js
– Lichter