Error: Unexpected value 'undefined' imported by the module

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

    My problem was having an export twice in index.ts

    Removing one of them solved the problem.

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

    In case your index exports a module - That module should not import its components from the same index, it should import them directly from the components file.

    I had this issue, and when I changed from importing the components in the module file using the index to importing them using the direct file, this resolved.

    e.g changed:

    import { NgModule } from '@angular/core';
    import { MainNavComponent } from './index';
    @NgModule({
      imports: [],
      exports: [MainNavComponent],
      declarations: [ MainNavComponent ],
      bootstrap:    [ MainNavComponent ]
    })
    export class MainNavModule {}
    

    to:

    import { NgModule } from '@angular/core';
    import { MainNavComponent } from './MainNavComponent';
    @NgModule({
      imports: [],
      exports: [MainNavComponent],
      declarations: [ MainNavComponent ],
      bootstrap:    [ MainNavComponent ]
    })
    export class MainNavModule {}
    

    also remove the now unnecessary exports from you index, e.g:

    export { MainNavModule } from './MainNavModule';
    export { MainNavComponent } from './MainNavComponent';
    

    to:

    export { MainNavModule } from './MainNavModule';
    
    0 讨论(0)
  • 2020-12-01 04:32

    For me, this error was caused by just unused import:

    import { NgModule, Input } from '@angular/core';
    

    Resulting error:

    Input is declared, but it's value never read

    Comment it out, and error doesn't occur:

    import { NgModule/*, Input*/ } from '@angular/core';
    
    0 讨论(0)
  • 2020-12-01 04:33

    Had the same exception when tried to compile an Angular 5 application.

    Unexpected value 'undefined' imported by the module 'DemoAppModule'
    

    In my case it turned out it was a circular dependency which I found by using a tool madge. Found the files containing circular dependency by running

    npx madge --circular --extensions ts src/
    
    0 讨论(0)
  • 2020-12-01 04:33

    I had the same issue, I added the component in the index.ts of a=of the folder and did a export. Still the undefined error was popping. But the IDE pop our any red squiggly lines

    Then as suggested changed from

    import { SearchComponent } from './';
    

    to

    import { SearchComponent } from './search/search.component';
    
    0 讨论(0)
  • 2020-12-01 04:33

    Unused "private http: Http" argument in the constructor of app.component.ts had caused me the same error and it resolved upon removing the unused argument of the constructor

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