我最近迁移了我的项目,使用Angular CLI打包我的项目。它使用“ng build”工作正常,但是当我尝试使用“ng build --prod”(反过来使用Angular AOT和其他附加步骤)时,我得到了这些错误:
ERROR in Cannot determine the module for class CustomDialog in F:/depot/depot/code/main/web/CedarsReport/src/a
pp/dialogs/customDialog.ts! Add CustomDialog to the NgModule to fix it.
Cannot determine the module for class ConfirmDialog in F:/depot/depot/code/main/web/CedarsReport/src/app/dialo
gs/confirmDialog.ts! Add ConfirmDialog to the NgModule to fix it.
Cannot determine the module for class EditUserDialog in F:/depot/depot/code/main/web/CedarsReport/src/app/dial
ogs/editUserDialog.ts! Add EditUserDialog to the NgModule to fix it.
Cannot determine the module for class LoginDialog in F:/depot/depot/code/main/web/CedarsReport/src/app/dialogs
/loginDialog.ts! Add LoginDialog to the NgModule to fix it.
Cannot determine the module for class EditAllControlsDlg in F:/depot/depot/code/main/web/CedarsReport/src/app/
dialogs/editAllControlsDlg.ts! Add EditAllControlsDlg to the NgModule to fix it.
Cannot determine the module for class EmptyTemplateDlg in F:/depot/depot/code/main/web/CedarsReport/src/app/di
alogs/emptyDialogTemplate.ts! Add EmptyTemplateDlg to the NgModule to fix it.
Cannot determine the module for class PopupSkeleton in F:/depot/depot/code/main/web/CedarsReport/src/app/direc
tives/popupSkeleton.ts! Add PopupSkeleton to the NgModule to fix it.
但是,大多数这些文件都在名为CRDialogs.module.ts的模块中引用:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; // ngFor, ngIf, ngStyle, and so on
import { Ng2Bs3ModalModule, ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal';
// Some dialogs use directives we've created
import { CRDirectives } from '../directives/CRDirectives.module';
// What we want to declare and export. Also, anything in 'imports' below is made available to all of these components
import { ChangePasswordDialog } from "./changePasswordDialog"
import { ConfirmDialog } from "./ConfirmDialog"
import { CreateShortcutDialog } from "./CreateShortcutDialog"
import { CustomDialog } from "./CustomDialog"
import { EditControlDlg } from "./EditControlDlg"
import { EditSectionDlg } from "./EditSectionDialog"
import { EditSitesDialog } from "./EditSitesDialog"
import { StandardFieldDialog } from "./editStandardFieldDialog"
import { EditUserDialog } from "./EditUserDialog"
import { ErrorsDialog } from "./ErrorsDialog"
import { GenericListDlg } from "./GenericListDialog"
import { LoginDialog } from "./LoginDialog"
import { ReferringPhysDialog } from "./ReferringPhysDialog"
import { SignReportDlg } from "./SignReportDlg"
@NgModule(
{
imports: [CommonModule, CRDirectives, Ng2Bs3ModalModule], // Other modules to import
declarations: [
ChangePasswordDialog, ConfirmDialog, CreateShortcutDialog, CustomDialog, EditControlDlg, EditSectionDlg, EditSitesDialog,
EditUserDialog, StandardFieldDialog, ErrorsDialog, GenericListDlg, LoginDialog, ReferringPhysDialog, SignReportDlg
],
exports: [
ChangePasswordDialog, ConfirmDialog, CreateShortcutDialog, CustomDialog, EditControlDlg, EditSectionDlg, EditSitesDialog,
EditUserDialog, StandardFieldDialog, ErrorsDialog, GenericListDlg, LoginDialog, ReferringPhysDialog, SignReportDlg
]
})
export class CRDialogs {}
这个模块反过来在我的app.module.ts中引用:
import { CRGlobals } from "./globals"
[...]
@NgModule({
declarations: [
CSReportMain,
AppTestTemp
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
CRDirectives,
**CRDialogs,**
CRPages,
[...]
],
providers: [
CRGlobals
],
bootstrap: [CSReportMain]
})
这里是main.ts:
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule);
那我为什么会收到这个错误?
答案 0 :(得分:1)
尝试进行实际的导入而不是仅仅将它们引用回CRDialogs.module.ts 我还注意到在main.ts中你只导入了app.module.ts,在app.module.ts中进行任何导入之前,你可能会先尝试导入CRDialogs.module.ts。
我是Angular的新手,我刚刚解决了类似的问题,我的问题是我没有在app.model.ts中进行正确的导入。我希望这有帮助