无法在 X.ts 中确定 class X 的模块!将 X 添加到 NgModule 以修复它在 ionic2 中的错误

Cannot determine the module for class X in X.ts! Add X to the NgModule to fix it error in ionic2

当我尝试使用以下命令构建我的应用程序时遇到问题:

ionic cordova run android --prod --release

一切 运行 都很好,如果我 运行 命令如下:

ionic cordova run android

我得到的错误是:

Error: Cannot determine the module for class CartItemsPage in C:/test/src/pages/cart/cart-items.ts! Add CartItemsPage to the NgModule to fix it. Cannot determine the module for class ItemsPage in C:/test/src/pages/items/items.ts! Add ItemsPage to th e NgModule to fix it. Cannot determine the module for class UserHomePage in C:/test/src/pages/user-home/user-home.ts! Add User HomePage to the NgModule to fix it. Cannot determine the module for class ForgotPasswordPage in C:/test/src/pages/forgot-password/forgot-pas sword.ts! Add ForgotPasswordPage to the NgModule to fix it. Cannot determine the module for class LoginPage in C:/test/src/pages/login/login.ts! Add LoginPage to th e NgModule to fix it. Cannot determine the module for class SignupPage in C:/test/src/pages/signup/signup.ts! Add SignupPage t o the NgModule to fix it. Cannot determine the module for class WelcomePage in C:/test/src/pages/welcome/welcome.ts! Add WelcomePa ge to the NgModule to fix it. Cannot determine the module for class PincodePage in C:/test/src/pages/pincode/pincode.ts! Add PincodePa ge to the NgModule to fix it. Cannot determine the module for class AppHomePage in C:/test/src/pages/app-home/app-home.ts! Add AppHome Page to the NgModule to fix it. Cannot determine the module for class ProfilePage in C:/test/src/pages/profile/profile.ts! Add ProfilePa ge to the NgModule to fix it. Cannot determine the module for class OrderDetailPage in C:/test/src/pages/myorders/order-detail.ts! Add OrderDetailPage to the NgModule to fix it. Cannot determine the module for class MyOrdersPage in C:/test/src/pages/myorders/myorders.ts! Add MyOrde rsPage to the NgModule to fix it. Cannot determine the module for class LogoutPage in C:/test/src/pages/logout/logout.ts! Add LogoutPage t o the NgModule to fix it. Cannot determine the module for class MyApp in C:/test/src/app/app.component.ts! Add MyApp to the NgModu le to fix it. Cannot determine the module for class RemoveUnderscorePipe in C:/test/src/utils/pipes/RemoveUnderscore.t s! Add RemoveUnderscorePipe to the NgModule to fix it.

但我已将所有页面和管道添加到 app.module.ts,如下所示:

// Imports

// The translate loader needs to know where to load i18n files
// in Ionic's static asset pipeline.
export function HttpLoaderFactory(http: Http) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}


let pages:any = [
  MyApp,
  LoginPage,
  UserHomePage,
  SignupPage,
  AppHomePage,
  WelcomePage,
  ItemsPage,
  CartItemsPage,
  ProfilePage,
  MyOrdersPage,
  OrderDetailPage,
  ForgotPasswordPage,
  PincodePage,
  LogoutPage
];

let pipes = [RemoveUnderscorePipe];

export function declarations() {
  return pages.concat(pipes);
}

export function entryComponents() {
  return pages;
}

export function providers() {
  return [
    Api,
    ItemsService,
    UserService,
    ToastService,
    CartService,
    OrdersService,
    TokenService,
    Camera,
    GoogleMaps,
    SplashScreen,
    StatusBar,

    // Keep this to enable Ionic's runtime error handling during development
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ];
}


@NgModule({
  declarations: declarations(),
  imports: [
    BrowserModule,
    HttpModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [Http]
      }
    }),
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot()
  ],
  bootstrap: [IonicApp],
  entryComponents: entryComponents(),
  providers: providers()
})
export class AppModule {
}

如果您看到我的 app.module.ts,我已经将组件和管道添加到入口组件和声明中。生产标志有什么我遗漏的吗? 我该如何解决这个问题?

将声明更改为如下所示的页面并且有效。

declarations: pages

我在 :https://forum.ionicframework.com/t/error-while-running-the-ionic3-app-in-production-mode/106294

得到了答案

这也可能是文件名大小写问题。见 https://github.com/angular/angular-cli/issues/10732

详细说明@[Thom Kiesewetter]的回答

也可能是路径大小写问题引用,用于模块路由 或其他地方

例如路径是

import { EmployeeComponent } from "./Entities/employee.component";

而不是

import { EmployeeComponent } from "./entities/employee.component";

真正的路径是“entities”而不是“Entities”

我遇到了同样的问题,但对我来说,有两个同名的组件如下所示,

my-first-app\src\app\header\header.component.ts

my-first-app\src\header\header.component.ts

第二个未使用且放置错误,因为我的所有代码仅在 my-first-app\src\app 内。我删除了第二个,它解决了我的问题。

我遇到了同样的问题,但对我来说,两个名称相似的组件多了一个“s”,

RigDeatilsInfoComponent

RigDetailInfoComponent

我们可以清楚的看到这里第一个组件名我有details和第二个组件名detail,还有angular 不区分这两者。

我通过将其中一个组件名称更改为 RigGeneralInfoComponent

解决了这个问题