I have been working on an almost complete Ionic app. Testing it has been smooth using the regular ionic build method and then creating an APK with Capacitor for testing purposes. However, things take a turn when I try to optimize my code using the --prod flag, as it throws a multitude of template errors that hinder the compilation process. Interestingly, these errors do not surface during regular builds.
Here are the steps to reproduce:
- Start with a functional version of the app (both for Android and web).
- Attempt to build a production version with 'ionic build --prod'.
Output:
Error: src/app/app.component.html:10:5 - error NG8001: 'ion-menu' is not a known element:
- If 'ion-menu' is an Angular component, then verify that it is part of this module.
- If 'ion-menu' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
This is a snippet from my output, specifically highlighting issues related to templates in the application.
Given below is the structure of my main module:
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
ComponentsModule,
FormsModule,
],
providers: [
ParseHandlerService,
StatusBar,
Geolocation,
SplashScreen,
AppStateService,
SpinnerService,
IconGetterService,
ReactiveChannel,
ImageResizer
],
bootstrap: [AppComponent]
})
Information about my Ionic setup:
`Ionic:
Ionic CLI : 6.11.1 (C:\Users\zerok\AppData\Roaming\npm\node_modules@ionic\cli) Ionic Framework : @ionic/angular 5.5.4 @angular-devkit/build-angular : 0.1101.4 @angular-devkit/schematics : 9.1.9 @angular/cli : 11.1.4 @ionic/angular-toolkit : 2.2.0
Capacitor:
Capacitor CLI : 2.4.6 @capacitor/core : 2.4.6
Utility:
cordova-res : not installed native-run : not installed
System:
NodeJS : v15.7.0 (C:\Program Files\nodejs\node.exe) npm : 6.14.11 OS : Windows 10`
EDIT: Sharing my app.component.html
file upon request
<div class="waiting" *ngIf="!appLoaded">
Loading data...
</div>
<ion-app *ngIf="appLoaded">
<ion-split-pane contentId="main">
<ion-menu side="start" menuId="first" contentId="main" [disabled]="userTraining" [maxEdgeStart]="15">
<ion-header>
<ion-toolbar>
<ion-title>My App</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list *ngIf="!userRef">
<ion-item *ngFor="let p of appPages" [routerDirection]="'root'" [routerLink]="[p.url]"
[queryParams]="p?.parameters ? p.parameters : null">
<ion-icon slot="start" [name]="p.icon" [style.color]="'#00c1ff'"></ion-icon>
<ion-label>
{{p.title}}
</ion-label>
</ion-item>
</ion-list>
<ion-list *ngIf="userRef">
<ion-menu-toggle auto-hide="false">
...
</ion-menu-toggle>
</ion-list>
</ion-content>
</ion-menu>
...
</ion-split-pane>
</ion-app>
UPDATE 2: Despite attempting to create a new project via ionic start
and meticulously transferring files and dependencies, including those in the package.json
, I continued to encounter the same errors while running ionic build --prod
. The persistent nature of these errors within 'app.component.html' hints at an underlying issue that eludes resolution.