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
Most probably the error will be related to the AppModule.ts file.
To solve this issue check whether every component is declared and every service that we declare is put in the providers etc.
And even if everything seems right in the AppModule file and you still get the error, then stop your running angular instance and restart it once again. That may solve your issue if everything in the module file is correct and if you are still getting the error.
For me the problem was solved by changing the import sequence :
One with I got the error :
imports: [
BrowserModule, HttpClientModule, AppRoutingModule,
CommonModule
],
Changed this to :
imports: [
BrowserModule, CommonModule, HttpClientModule,
AppRoutingModule
],
I am building a components library and started getting this error in my app that is importing said library. When running ng build --prod
or ng serve --aot
in app I would get:
Unexpected value 'undefined' imported by the module 'ɵm in node_modules/<library-name>/<library-name>.d.ts'
But no errors when using ng serve
or when testing the modules in the library itself even when building in --prod
.
Turns out I was misled by intellisense as well. For a few of my modules I had imported a sister module as
import { DesignModule } from '../../design';
instead of
import { DesignModule } from '../../design/design.module';
It worked in fine in all builds except the one I described.
This was terrible to pin down and I was lucky it didn't take me longer than it did. Hope this help someone.
My problem was a misspelled component name inside the component.ts
.
The import statement didn't show an error but the declaration did, which misled me.
For anyone facing this same error, my situation was that I have double commas in the imports section
imports: [
BrowserModule,
HttpModule,
FormsModule,
RouterModule.forRoot(appRoutes), , // <-- this was the error
// ....
],
I had this error because I had an index.ts
file in the root of my app that was exporting my app.component.ts
. So I thought I could do the following:
import { AppComponent } from './';
This worked and gave me no red squiggly lines and even intellisense brings up AppComponent when you start typing it. But come to find out it was causing this error. After I changed it to:
import { AppComponent } from './app.component';
The error went away.