Error: Unexpected value 'undefined' imported by the module

前端 未结 30 1629
礼貌的吻别
礼貌的吻别 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:43

    I had the same problem. In my case, the reason is an extra comma.

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

    I met this problem at the situation: - app-module --- app-routing // app router ----- imports: [RouterModule.forRoot(routes)] --- demo-module // sub-module ----- demo-routing ------- imports: [RouterModule.forRoot(routes)] // --> should be RouterModule.forChild!

    because there is only a root.

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

    This can be caused by multiple scenarios like

    1. Missing commas
    imports: [
        BrowserModule
       ,routing <= Missing Comma
       ,FeatureComponentsModule
      ],
    
    1. Double Commas
    imports: [
        BrowserModule, 
       ,routing <=Double Comma
       ,FeatureComponentsModule
      ],
    
    1. Exporting Nothing from the Module
    2. Syntax errors
    3. Typo Errors
    4. Semicolons inside Objects, Arrays
    5. Incorrect import Statements
    0 讨论(0)
  • 2020-12-01 04:49

    Another reason could be some code like this:

    import { NgModule } from '@angular/core';
    import { SharedModule } from 'app/shared/shared.module';
    import { CoreModule } from 'app/core/core.module';
    import { RouterModule } from '@angular/router';
    import { COMPANY_ROUTES } from 'app/company/company.routing';
    import { CompanyService } from 'app/company/services/company.service';
    import { CompanyListComponent } from 'app/company/components/company-list/company-list.component';
    
    @NgModule({
        imports: [
            CoreModule,
            SharedModule,
    		RouterModule.forChild(COMPANY_ROUTES)
        ],
        declarations: [
    		CompanyListComponent
        ],
        providers: [
    		CompanyService
        ],
        exports: [
        ]
    })
    export class CompanyModule { }

    Because exports is empty array and it has , before it, it should be removed.

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

    I was facing the same problem. Issue was that I was importing some class from index.ts

        import {className} from '..shared/index'
    

    index.ts contain the export statement

        export * from './models';
    

    I changed it to the .ts file which contain the actual class object

        import {className} from '..shared/model'
    

    and it resolved.

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

    This issue of circular dependencies of two module

    Module 1:import Module 2
    Module 2:import Module 1

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