Error: Unexpected value 'undefined' imported by the module

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

    You have to remove line import { provide } from '@angular/core'; from app.module.ts as provide is deprecated now. You have to use provide as below in providers :

    providers: [
        {
          provide: APP_BASE_HREF,
          useValue: '<%= APP_BASE %>'
        },
        FormsModule,
        ReactiveFormsModule,
        // disableDeprecatedForms(),
        // provideForms(),
        // HTTP_PROVIDERS, //DGF needed for ng2-translate
        // TRANSLATE_PROVIDERS, //DGF ng2-translate (not required, but recommended to have 1 unique instance of your service)
        {
            provide : TranslateLoader,
            useFactory: (http: Http) => new TranslateStaticLoader(http, 'assets/i18n', '.json'),
            deps: [Http]
        },
        {
            provide : MissingTranslationHandler,
            useClass: TranslationNotFoundHandler
        },
    
        AuthGuard,AppConfigService,AppConfig,
        DateHelper
      ]
    
    0 讨论(0)
  • 2020-12-01 04:51

    None of the above solutions worked for me, but simply stopping and running "ng serve" again.

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

    The issue is that there is at least one import for which source file is missing.

    For example I got the same error when I was using

           import { AppRoutingModule } from './app-routing.module';
    

    But the file './app-routing.module' was not there in given path.

    I removed this import and error went away.

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

    I had the same error, none of above tips didn't help.

    In my case, it was caused by WebStorm, combined two imports into one.

    import { ComponentOne, ComponentTwo } from '../component-dir';
    

    I extracted this into two separate imports

    import { ComponentOne } from '../component-dir/component-one.service';
    import { ComponentTwo } from '../component-dir/component-two.model';
    

    After this it works without error.

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

    The Solutions above do not worked for me.

    So I back the version of angular-cli of 1.6.4 for 1.4.4 and this solved my problem.

    I do not know if this is the best solution, but for now, this worked for me

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

    Make sure you should not import a module/component like this:

    import { YOUR_COMPONENT } from './';
    

    But it should be

    import { YOUR_COMPONENT } from './YOUR_COMPONENT.ts';
    
    0 讨论(0)
提交回复
热议问题