Error: Unexpected value 'undefined' imported by the module

前端 未结 30 1627
礼貌的吻别
礼貌的吻别 2020-12-01 03:51

I\'m getting this error after migrating to NgModule, the error doesn\'t help too much, any advice please?

Error: Error: Unexpected value \'undefined\' import         


        
相关标签:
30条回答
  • 2020-12-01 04:34

    Just putting the provider inside the forRoot works: https://github.com/ocombe/ng2-translate

    @NgModule({
      imports: [BrowserModule, HttpModule, RouterModule.forRoot(routes), /* AboutModule, HomeModule, SharedModule.forRoot()*/
              FormsModule,
              ReactiveFormsModule,
              //third-party
              TranslateModule.forRoot({
                provide: TranslateLoader,
                useFactory: (http: Http) => new TranslateStaticLoader(http, '/assets/i18n', '.json'),
                deps: [Http]
              })
              //third-party PRIMENG
              ,CalendarModule,DataTableModule,DialogModule,PanelModule
      ],
      declarations: [
        AppComponent,ThemeComponent, ToolbarComponent, RemoveHostTagDirective,
        HomeComponent,MessagesExampleComponent,PrimeNgHomeComponent,CalendarComponent,Ng2BootstrapExamplesComponent,DatepickerDemoComponent,UserListComponent,UserEditComponent,ContractListComponent,AboutComponent
      ],
      providers: [
        {
          provide: APP_BASE_HREF,
          useValue: '<%= APP_BASE %>'
        },
        // FormsModule,
        ReactiveFormsModule,
        { provide : MissingTranslationHandler, useClass: TranslationNotFoundHandler},
        AuthGuard,AppConfigService,AppConfig,
        DateHelper
      ],
      bootstrap: [AppComponent]
    })
    
    export class AppModule { }
    
    0 讨论(0)
  • 2020-12-01 04:34

    As long as you are sure you are not doing anything wrong, kindly terminate "ng serve" and restart it. By so doing, the compiler does all of its work and the app serves as expected. Prior experiences with modules have taught me to either create them when "ng serve" is not running or to restart the terminal once I'm done.

    Restarting "ng serve" also works when you're emitting a new component to another component, it's possible the compiler has not recognised your new component, simply restart "ng serve"

    This worked for me just a few minutes ago.

    0 讨论(0)
  • 2020-12-01 04:38

    there is another simple solution for this. I have 2 modules which are somehow deep in the structure using each other. I ran into the same problem with circular dependencies with webpack and angular 2. I simply changed the way of how the one module is declared:

    ....
    
    @NgModule({
        imports: [
            CommonModule,
            FormsModule,
            require('../navigation/navigation.module')
        ],
        declarations: COMPONENTS,
        exports: COMPONENTS
    })
    class DppIncludeModule {
        static forRoot(): ModuleWithProviders {
            return {
                ngModule: DppIncludeModule
            };
        }
    }
    
    export = DppIncludeModule;
    

    When I now using the imports statement on ngModule attribute I simply use:

    @NgModule({
        imports: [
            CommonModule,
            ServicesModule.forRoot(),
            NouisliderModule,
            FormsModule,
            ChartModule,
            DppAccordeonModule,
            PipesModule,
            require('../../../unbranded/include/include.module')
        ],
    ....
    

    With this all problems are away.

    0 讨论(0)
  • 2020-12-01 04:39

    I fix it by delete all index export file, include pipe, service. then all file import path is specific path. eg.

    import { AuthService } from './_common/services/auth.service';

    replace

    import { AuthService } from './_common/services';

    besides, don't export default class.

    0 讨论(0)
  • 2020-12-01 04:40

    Make sure the modules don't import each other. So, there shouldn't be

    In Module A: imports[ModuleB]

    In Module B: imports[ModuleA]

    0 讨论(0)
  • 2020-12-01 04:42

    I had this issue, it is true that the error on the console ain't descriptive. But if you look at the angular-cli output:

    You will see a WARNING, pointing to the circular dependency

    WARNING in Circular dependency detected:
    module1 -> module2
    module2 -> module1
    

    So the solution is to remove one import from one of the Modules.

    0 讨论(0)
提交回复
热议问题