@ngtools/webpack complainning about not an NgModule
using @ngtools/webpack 1.1.7
tried both @angular/compiler-cli 2.1.x and 2.2.0
import { NgModule, Component } from '@angular/core';
@Component({
selector: 'app',
template: '<h1>hello world</h1>',
styles: []
})
class AppComponent {}
@NgModule({
declarations: [AppComponent],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
Error: AppModule is not an NgModule
at AotPlugin.getNgModuleMetadata (/var/build/node_modules/@ngtools/webpack/src/plugin.js:297:19)
at AotPlugin._processNgModule (/var/build/node_modules/@ngtools/webpack/src/plugin.js:241:42)
at /var/build/node_modules/@ngtools/webpack/src/plugin.js:217:39
at process._tickCallback (internal/process/next_tick.js:103:7)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:394:7)
Done in 7.29s.
@princemaple can you paste your AotPlugin configuration, please?
oops, I missed this is an angular-cli related.
Without it (i.e. just using @ngtools/webpack), that error message would appear if entryModule points to the wrong path (i.e. ' ./src/app/app.module#AppModule' must be a valid path)
I had a very simple minimal AotPlugin config, something like
new ngtools.AotPlugin({
tsConfigPath: '/var/build/tsconfig.json',
entryModule: '/var/build/src/app.module#AppModule'
})
Note I used absolute paths, because I saw some commits in this repo saying something about relative paths not working. I am pretty sure my path was valid.
I see. In that case, I have no more to add.
I have the same problem here. I also configured it like @princemaple. BTW: I have not defined any entry point.
@marinho thanks for taking a look still!
AotPlugin.prototype.getNgModuleMetadata = function (staticSymbol) {
var ngModules = this._reflector.annotations(staticSymbol).filter(function (s) {
return s instanceof core_1.NgModule;
});
if (ngModules.length === 0) {
throw new Error(staticSymbol.name + " is not an NgModule");
}
return ngModules[0];
};
Whereas staticSymbol is...
{
filePath: '/Users/***skipped***/client/app/app.module.ts',
name: 'AppModule',
members: undefined
}
...and this._reflector.annotations(staticSymbol) is [].
Seems like the annotations are not set correctly? The path is valid.
@janwo did you try without ".ts" in filePath?
When enabling AoT, it didn't pass because I had some imports with .ts in the end. I just removed in all lines it found and it didn't complain anymore. Maybe it's the same case.
BTW, I still don't have my app successfully in AoT. I'm also learning in this topic at this very moment.
@marinho Thanks for your response. Yes, its all without a suffix. Somehow it works now, I deleted my node_modules folder and installed all dependencies again. It's weird as I updated them before as well.
I have the same problem, see https://github.com/angular/angular-cli/issues/2667
Im also getting the same. If I build a new project using ng new and run -aot on that, it works fine - but on my own project im getting Error: AppModule is not an NgModule. I have removed everything from my AppModule and AppComponent.
I have the problem with the AotPlugin for Webpack...
It seems like [email protected] is causing the issue. Downgrading to 2.0.10 seems to make it pick up the metadata correctly.
Strangely, this error shows up on 2.2.4 but not 2.2.3.
For me downgrading to [email protected] worked, just like jessezhang91 suggested.
@zakdances thanks for heads up. Will skip this update :) Previous dancing with this error is hard to forget.
Downgrading to 2.0.12 didnt work for me. :( When I run ng server --aot I still get this error. (double checked the installed version as well)
2.0.12 != 2.0.10
Sorry, I meant to write 2.0.10.