Hello,
Recently I was trying to generate production build of one of our older Angular app which was built on Angular 6 and later upgraded to Angular 7. When we run ng build it works fine but when we run ng build --prod it gives so many errors.
Here in this blog I am going to explain what are those errors and how I solved it.
Problem 1 : Strict Parameter checking for function.
There were few events and handler defined in the app where there were parameter mismatch. For example in html file we have following event.
<componentName (event)="eventHandler($event)"></componentName >
And in component TS file event handler was defined like this
eventHandler() {
}
As you can see from html file it was passing $event param but on handler param was not mentioned. So make sure that your function signature and function declaration matches.
Problem 2 : Duplicate Declaration of Components
By mistake we have duplicate declaration of components in both App module and and other child modules of the app. Make sure you either declare all your components to app module or if you are defining it into sub module then make sure you remove it from app module.
Problem 3 : Cannot read property 'moduleType' of undefined
When you face above issue please check your app module by mistake you may have defined following line twice in your app module.
platformBrowserDynamic().bootstrapModule(AppModule);
It's like you are trying to bootstrap your Angular app twice and it gives above error. So try to avoid it.
Problem 4 : Enable IVY
In Angular 7 by default IVY is disabled hence even if you generate production build you app size it bit large. To enable IVY add following line to your tsconfig.json file.
"angularCompilerOptions": {
"enableIvy": true
}
Recently I was trying to generate production build of one of our older Angular app which was built on Angular 6 and later upgraded to Angular 7. When we run ng build it works fine but when we run ng build --prod it gives so many errors.
Here in this blog I am going to explain what are those errors and how I solved it.
Problem 1 : Strict Parameter checking for function.
There were few events and handler defined in the app where there were parameter mismatch. For example in html file we have following event.
<componentName (event)="eventHandler($event)"></componentName >
And in component TS file event handler was defined like this
eventHandler() {
}
As you can see from html file it was passing $event param but on handler param was not mentioned. So make sure that your function signature and function declaration matches.
Problem 2 : Duplicate Declaration of Components
By mistake we have duplicate declaration of components in both App module and and other child modules of the app. Make sure you either declare all your components to app module or if you are defining it into sub module then make sure you remove it from app module.
Problem 3 : Cannot read property 'moduleType' of undefined
When you face above issue please check your app module by mistake you may have defined following line twice in your app module.
platformBrowserDynamic().bootstrapModule(AppModule);
It's like you are trying to bootstrap your Angular app twice and it gives above error. So try to avoid it.
Problem 4 : Enable IVY
In Angular 7 by default IVY is disabled hence even if you generate production build you app size it bit large. To enable IVY add following line to your tsconfig.json file.
"angularCompilerOptions": {
"enableIvy": true
}
Hope this blog post helps you.
No comments:
Post a Comment