Issue with Typescript - Node.js + Ionic mobile app's Angular AoT build has encountered an error

Currently, I am in the process of developing an Android application using Node.js and Ionic framework. The app is designed to display random text and images stored in separate arrays. While testing the app on Chrome, everything works perfectly fine.

Upon running the 'ionic serve' command in the terminal, Random1 feature displays both a random text and image when clicking the next button, while Random2 only shows a random image. However, when attempting to run the 'ionic cordova run android --prod --release' command, an error occurs:

[16:54:50]  build prod started ...
[Error message displayed here]

I ran this command from the root folder of the Ionic app, which contains various directories including:

Link to image directory

Am I executing the command from the correct location?

Here are snippets from key files in the project:

random1.ts:

[Code snippet for Random1Page component]

app.module.ts:

[Code snippet for AppModule]

Answer №1

It's unclear from your query whether you are interested in utilizing Lazy-loaded pages. Implementing lazy-loading can enhance the performance of your application. If you do opt for lazy-loaded pages, the subsequent steps will assist you in resolving the issue at hand.

If lazy-loaded pages are not part of your app requirements, refer to @Sampath's response instead.


Upon adding @IonicPage() above any of your pages:

@IonicPage() // <-- This line!
@Component({
  selector: 'page-random1',
  templateUrl: 'random1.html',
})
export class Random1Page { ... }

This indicates that the page will be lazy loaded. Furthermore, ensure there is a random1.module.ts file present in the same directory as that page, like so:

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { Random1Page } from './random1';

@NgModule({
  declarations: [
    Random1Page,
  ],
  imports: [
    IonicPageModule.forChild(Random1Page),
  ],
})
export class Random1PageModule {}

As evident from the preceding file, Random1Page is included in the Random1PageModule module.

Returning to the error you have encountered:

typescript error Type Random1Page in C:/.../pages/random1/random1.ts is part of the declarations of 2 modules: AppModule in C:/.../app/app.module.ts and Random1PageModule in C:/.../pages/random1/random1.module.ts!

To rectify this, it is necessary to remove that page (along with all other lazy-loaded pages) from the AppModule located within the app.module.ts file:

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';

import { MyApp } from './app.component';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

@NgModule({
  declarations: [
    MyApp
    // HomePage,
    // ListPage,
    // Random1Page, <-- Remove it from here
    // Random2Page,
    // LoggedinPage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp
    // HomePage,
    // ListPage,
    // Random1Page, <-- Also remove it from here
    // Random2Page,
    // LoggedinPage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

You can explore more details on lazy-loading in the Ionic blog:

  • Ionic and Lazy Loading Pt 1
  • Ionic and Lazy Loading Pt 2

Answer №2

When you ran the latest CLI command ionic generate page Random1Page, it automatically generated a lazy loaded module called Random1PageModule for you. However, it appears that your app is not currently utilizing lazy loading. To resolve this, you should delete the Random1PageModule module located in your page's folder.

In the future, if you do not want to use Lazy loading pages, you can create a page using the following CLI command:

ionic generate page Random1Page --no-module

Note: I strongly advise implementing Lazy loading as it can significantly improve your app's performance.

For more information on lazy loading, you can refer to this lazy loading article.

Answer №3

Give this command a shot:

npm install @ionic/app-scripts@latest --save-dev

It did the trick for me.

If that doesn't work, you can try downgrading the app-script dependency in your package.json like so:

Change

"@ionic/app-scripts": "3.2.4"

to

"@ionic/app-scripts": "3.2.3"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Vitest surpasses Jest by providing explicit type declarations, ensuring no more "unknown type" errors

Transitioning from Jest to vitest has been a smooth process for me. I'm currently in the midst of converting the following code snippets: // Jest const myLib = jest.requireActual("mylib.js") to this: // Vitest const myLib = await vi.importA ...

Create and save data to a local file using Angular service

I am facing an issue with my Angular service: import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { person } from '../interfaces/iperson ...

Error: Local variable remains undefined following an HTTP request

Whenever I make http calls, my goal is to store the received JSON data in a local variable within my component and then showcase it in the view. Service: getCases(){ return this.http.get('someUrl') .map((res: Response) => res.jso ...

Exploring the power of chaining multiple subscriptions in RxJs 6

I have a project using Angular 6, and I'm currently in the process of upgrading rxjs to version 6. In the previous iteration of my app, there was a specific flow where I needed to make sequential calls to observables: 1. Call an observable 2. Perfor ...

Configuring TypeScript for Firefox to recognize specific types such as browser.storage

As per the documentation from Mozilla, I should be able to utilize browser.storage.sync.get in my extension. However, I am encountering some challenges in getting TypeScript to recognize that I can use browser. I have attempted the following (which has wo ...

Merge arrays values with Object.assign function

I have a function that returns an object where the keys are strings and the values are arrays of strings: {"myType1": ["123"]} What I want to do is merge all the results it's returning. For example, if I have: {"myType1": ["123"]} {"myType2": ["45 ...

The parameter type '(req: Request, res: Response, next: NextFunction) => void' does not match the type of 'Application<Record<string, any>>'

I'm currently working on an Express project that utilizes TypeScript. I have set up controllers, routers, and implemented a method that encapsulates my controller logic within an error handler. While working in my router.ts file, I encountered an err ...

Choose the material and eliminate any gaps

Is there a preferred method for eliminating empty space in Material select/input fields? I am looking to ensure the field width matches the content size. https://i.stack.imgur.com/ZmgKK.png Visit https://material.angular.io/components/select/overview for ...

Connect a click event from one component to another component

Can Angular bind a click event dynamically from a component to another existing component on the page? Check out this image for reference. In my app, I have 4 simple components - a shell component that defines the layout, a header component (blue outline) ...

How can I display an error message if the checkbox is not selected upon form submission?

If none of the checkboxes are selected, an error message should be displayed. The error message should be hidden when a checkbox is checked, but it's currently visible initially and disappears when unchecked. I would greatly appreciate your help. Than ...

Using NextJS's API routes to implement Spotify's authorization flow results in a CORS error

I am currently in the process of setting up the login flow within NextJS by referring to the guidelines provided in the Spotify SDK API Tutorial. This involves utilizing NextJS's api routes. To handle this, I've created two handlers: api/login.t ...

Is there a way to effectively refresh in Angular while using JBoss 6.4?

In my configuration of the standalone.xml file, I have set up the following rules inside subsystem tags: <rewrite name="rule-2" pattern="^((?!.*(rest)).*)\/([\w\-]+)\/([\w\-]+)$" substitution="/$1/index.html" flags="L"/> ...

TS2304: The build process is unable to locate the name 'iterable' within @types

As an experienced dog attempting to master new tricks like npm and TypeScript, I find myself faced with a challenge in my Visual Studio 2017 project. Despite setting it to "Latest" TypeScript 2.5 and adding @types/jquery (3.2.12), the project keeps throwin ...

Minimize the count of switch cases that are not empty

How can I optimize the number of cases in my switch statement to align with SonarQube recommendations? Currently, I have 37 cases in a switch statement, but SonarQube recommends only 30. I believe that my code is functioning correctly, and the issue lies ...

The specified main access point, "@angular/cdk/platform", is lacking in required dependencies

I recently updated my Angular app from version 8 to version 9. After resolving all compilation and linter errors, I encountered one specific issue that is causing me trouble: ERROR in The target entry-point "@angular/cdk/platform" has missing dep ...

Mixing pipe operators with Angular Observables in an array

In my project, I have an interesting scenario where I am using Observables and piping them to multiple functions as shown below. getOrders(filters: any, page: any = 1, orderBy: string = 'deliver_on', sort: string = 'asc') { const op ...

The ngx-image-cropper's roundCropper attribute is not functioning correctly as it should. An error is being displayed stating: "Type 'string' is not assignable to type 'boolean'"

<image-cropper [imageChangedEvent]="imageChangedEvent" [maintainAspectRatio]="true" [aspectRatio]="4 / 4" format="jpg" (imageCropped)="imageCropped($event)" roundCropper = "true"> </i ...

Distinguishing variations within subcategories that stem from a common origin

In my code example, I have two interfaces that both extend a common base interface. The "String" function takes an argument of type "StringAsset". My expectation was that if I were to call the "String" function and pass it a value of "NumberAsset", TypeScr ...

What advantages does NgRx offer that Signal does not provide?

Signals are a recent addition to the Angular framework. In comparison to Signals, what unique benefits does the NgRx component store or other state management options provide? Are there any functionalities offered by the NgRx component store that cannot ...

It can be time-consuming to render a large quantity of dynamic markers on Leaflet after receiving a response

Incorporating leaflet.js into my web project, I am faced with the challenge of creating a map view with dynamic markers. Upon receiving a response, I attempt to generate dynamic components based on the data and utilize change detection to monitor updates. ...