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
My problem was having an export twice in index.ts
Removing one of them solved the problem.
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';
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';
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/
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';
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