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

Inspect the TypeScript typings within Svelte documents directly from the terminal

When I run tsc --noemit, it successfully checks for type errors in the codebase. However, I have encountered an issue where it does not seem to check .svelte files. Is there a way to enable this functionality? I can see the type errors in .svelte files wh ...

I encountered an issue in my Angular application where I continually receive the error message stating "Module 'fs' cannot be found."

Within my service file, I have imported four crucial libraries: import * as async from "async"; import * as officegen from "officegen"; import * as path from "path"; import * as fs from "fs"; All seems to be functioning well with async, officegen, and pa ...

Ionic Beta 10 iOS Build - You are attempting to create an iOS build without having the platform installed

After smoothly developing for Android on a Windows computer, I recently switched to a Mac Mini. Once I updated the OS to El Capitan, installed XCode, and set up everything else (NodeJS, Ionic, etc.), I attempted to build for iOS only to encounter the follo ...

Enhancing a UMD module definition with TypeScript 2: A step-by-step guide

Currently, I am in the process of creating TypeScript definition files for two libraries that are meant to be used with the new @types approach. Both libraries adhere to the UMD pattern, allowing them to be consumed either as modules or by referencing them ...

Typescript: Ways to fix the error 'rxjs/Rx does not have any exported member 'SubscriptionLike'

I'm attempting to replicate the steps outlined in this tutorial found here https://www.youtube.com/watch?v=gxCu5TEmxXE. However, upon running tsc -p, I encounter an error. Is there a specific import that I am missing? ERROR: node_modules/@angular/co ...

Sending properties via react router link in TypeScript

I have successfully defined my routes and made my links functional. I am now trying to figure out how to pass a prop through the link when the component is called by the router. It seems like a challenging task. To understand better, take a look at this c ...

Which superclass does ReadonlyArray extend from?

Looking at this TypeScript code snippet: const arr: ReadonlyArray<string> = [ "123", "234" ]; arr.push("345"); An error is thrown by the TS compiler: Property 'push' does not exist on type 'ReadonlyArray<string>&apo ...

Inputting Dates Manually in the Angular Material Datepicker Field

The datepicker function works well unless I manually type in the date. When I input a date between 01.MM.YYYY and 12.MM.YYYY, the value switches to MM.DD.YYYY. However, if I input 16.09.2021 for example, it remains as DD.MM.YYYY. Is there a way to change ...

Angular2/Typescript: Transforming a Javascript/Typescript Date into a C# DateTime string on the client side

Currently immersed in an Angular2/Typescript project, I am faced with the task of sending a date to a C# backend. Despite my extensive research, all I could uncover through Google searches was information on converting the date on the backend side. My la ...

Issue encountered: Dealing with a deadlock error triggered by a single query following the

I have a question about managing a query that runs across multiple micro-services, which can sometimes lead to deadlocks. const handleExecution = async (id: number): Promise<boolean> => { try { const query = ` UPDATE articles a1 ...

What is the most reliable way to create an array ensuring that all potential values come from a specific dictionary?

I am seeking a method to define the testArray so that only keys from the example dictionary can be inserted into the array. enum example { key1 = 'A', key2 = 2, key3 = '3', }; const testArray: ?? = [example.key1, example.ke ...

The Angular project I am hosting on GitHub Pages seems to be having trouble locating its files, leading to a

After successfully building an Angular project using the ng build command, I ran into an issue when uploading it to a GitHub repository and creating its GitHub Page. Despite working perfectly locally, none of the bundle files could be found when accessing ...

Retrieve a specific subdirectory from the bundle

I've developed a Typescript package with the following file structure: package.json src/ index.ts common/ index.ts sub/ index.ts My goal is to import certain modules from the package like this: import {...} from '<package>&ap ...

In a Custom Next.js App component, React props do not cascade down

I recently developed a custom next.js App component as a class with the purpose of overriding the componentDidMount function to initialize Google Analytics. class MyApp extends App { async componentDidMount(): Promise<void> { await initia ...

The child object in Typescript is characterized by its strong typing system

Looking to convert plain AngularJS code to Typescript? Take a look at this example: app.someController = function ($scope) { // var $scope.Data = null; var $scope.Data: SomeCollection = null; I need to associate Data with scope and specify it as type ...

Implementing Express.js allows for the seamless casting of interfaces by the body within the request

I have created a similar structure to ASP.NET MVC and uploaded it on my github repository (express-mvc). Everything seems fine, but I am facing an issue with casting the body inside the request object to match any interface. This is what I am aiming for: ...

Change typescript so that it shows "require" instead of "import" when outputting

Currently, I am converting TypeScript code to JavaScript for an application that is specifically targeting Node v.14. My goal is to have the output contain require statements instead of import statements. This is what my configuration file looks like: { ...

Is there a way to apply the same technique to a dynamic select option in Angular?

My array is dynamic and has an onChange method in the select option. The issue arises when I add a new array and select the new option, as it causes the first array to reset. Here's a snippet of my array structure: <ng-container formGroupName=&qu ...

What is the equivalent of specifying globalDevDependencies for npm @types packages in typings?

I am looking to update a project using tsc@2 and remove typings from my toolchain. Updating common dependencies is easy as they are listed in my typings.json file: "dependencies": { "bluebird": "registry:npm/bluebird#3.3.4+20160515010139", "lodash": ...

Having trouble locating a module while implementing lazy loading in an Angular project

I've managed to set up an Angular project successfully on a Mac environment. Angular CLI: 7.0.5 Node: 8.11.3 OS: darwin x64 Angular: 7.0.3 Now, I'm attempting to run the same code on Ubuntu 18.04 with the following setup: Angular CLI: 7.3.9 No ...