angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

@ngtools/webpack complainning about not an NgModule

Open princemaple opened this issue 10 years ago • 71 comments

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 avatar Nov 16 '16 11:11 princemaple

@princemaple can you paste your AotPlugin configuration, please?

marinho avatar Nov 17 '16 03:11 marinho

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)

marinho avatar Nov 17 '16 03:11 marinho

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'
})

princemaple avatar Nov 17 '16 03:11 princemaple

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.

princemaple avatar Nov 17 '16 03:11 princemaple

I see. In that case, I have no more to add.

marinho avatar Nov 17 '16 05:11 marinho

I have the same problem here. I also configured it like @princemaple. BTW: I have not defined any entry point.

janwo avatar Nov 17 '16 08:11 janwo

@marinho thanks for taking a look still!

princemaple avatar Nov 17 '16 08:11 princemaple

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 avatar Nov 17 '16 14:11 janwo

@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 avatar Nov 18 '16 07:11 marinho

@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.

janwo avatar Nov 18 '16 12:11 janwo

I have the same problem, see https://github.com/angular/angular-cli/issues/2667

dhardtke avatar Nov 18 '16 18:11 dhardtke

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.

mashhoodr avatar Nov 22 '16 16:11 mashhoodr

I have the problem with the AotPlugin for Webpack...

dhardtke avatar Nov 22 '16 22:11 dhardtke

It seems like [email protected] is causing the issue. Downgrading to 2.0.10 seems to make it pick up the metadata correctly.

jessezhang91 avatar Nov 22 '16 22:11 jessezhang91

Strangely, this error shows up on 2.2.4 but not 2.2.3.

zakdances avatar Dec 02 '16 12:12 zakdances

For me downgrading to [email protected] worked, just like jessezhang91 suggested.

dhardtke avatar Dec 02 '16 12:12 dhardtke

@zakdances thanks for heads up. Will skip this update :) Previous dancing with this error is hard to forget.

e-oz avatar Dec 02 '16 12:12 e-oz

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)

mashhoodr avatar Dec 02 '16 12:12 mashhoodr

2.0.12 != 2.0.10

dhardtke avatar Dec 02 '16 12:12 dhardtke

Sorry, I meant to write 2.0.10.

mashhoodr avatar Dec 02 '16 12:12 mashhoodr