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

@zakdances downgrading all packages to 2.2.3 didn't work for me..:( Which packages did you downgraded to 2.2.3 exactly?? Thanks

DutchKevv avatar Dec 02 '16 23:12 DutchKevv

@DutchKevv make sure you downgrade router to 3.2.3 or so as well.

jessezhang91 avatar Dec 03 '16 01:12 jessezhang91

Thanks Jess, but didn't get it to work..

Using these packages ->

"@angular/common": "2.2.3", "@angular/compiler": "2.2.3", "@angular/core": "2.2.3", "@angular/forms": "2.2.3", "@angular/http": "2.2.3", "@angular/platform-browser": "2.2.3", "@angular/platform-browser-dynamic": "2.2.3", "@angular/router": "3.2.3", "@ngrx/core": "^1.2.0", "@ngrx/effects": "^2.0.0", "@ngrx/store": "2.2.1", "@ngrx/store-devtools": "^3.2.1", "@ngrx/store-log-monitor": "^3.0.2",

Probably just wait until Typescript and Angular are friends again on final releases.. But can't build production now :(

DutchKevv avatar Dec 04 '16 19:12 DutchKevv

@DutchKevv try to rm -rf npm_modules && npm cache clean before installation.

e-oz avatar Dec 04 '16 19:12 e-oz

I think this issue is related to [email protected] and tsc-wrapped as dhardtke and jessezhang91 said.

In https://github.com/angular/angular/blob/2.2.x/tools/@angular/tsc-wrapped/src/collector.ts#L254 , which collects metadata from app.module.ts ,

        case ts.SyntaxKind.ClassDeclaration:
          const classDeclaration = <ts.ClassDeclaration>node;
          if (classDeclaration.name) {
            const className = classDeclaration.name.text;
            if (node.flags & ts.NodeFlags.Export) { // this is false always! 
              if (classDeclaration.decorators) {
                if (!metadata) metadata = {};
                metadata[className] = classMetadataOf(classDeclaration);
              }
            }
          }

this code works only if node.flags & ts.NodeFlags.Export g.t. 0. But in https://github.com/Microsoft/TypeScript/blob/v2.1.1/src/compiler/types.ts#L400 , there is no export enum named Export. (In [email protected] ts.NodeFlags has the Export value. see https://github.com/Microsoft/TypeScript/blob/v2.0.10/src/compiler/types.ts#L395 )

Quramy avatar Dec 04 '16 19:12 Quramy

I'm getting the same error using TypeScript 2.0.10, trying to link modules from 1 app into another. Both are generated using angular-cli version 1.0.0-beta.22.

beeman avatar Dec 05 '16 23:12 beeman

Yep same problem here with "typescript": "2.0.10" and "angular-cli": "1.0.0-beta.22-1" any solutions ?

tarlepp avatar Dec 06 '16 12:12 tarlepp

not working even with typescript 2.0.10, using @ngtools/webpack 1.1.9

0% compilingError: AppModule is not an NgModule
    at AotPlugin.getNgModuleMetadata (/Users/antony/Documents/Code/Web/angular-webpack-starter/node_modules/@ngtools/webpack/src/plugin.js:332:19)
    at AotPlugin._processNgModule (/Users/antony/Documents/Code/Web/angular-webpack-starter/node_modules/@ngtools/webpack/src/plugin.js:271:42)
    at /Users/antony/Documents/Code/Web/angular-webpack-starter/node_modules/@ngtools/webpack/src/plugin.js:242:39

reproduction repo, just update the package.json for ngtools and angular packages


fixed, following updates from https://github.com/angular/angular-cli/commit/45d5154

antonybudianto avatar Dec 06 '16 13:12 antonybudianto

@tarlepp @antonybudianto Workaround: Specify the precise dependency versions in the package.json.

ghost avatar Dec 06 '16 15:12 ghost

@timosalm already did, it's breaking after @ngtools 1.1.6

antonybudianto avatar Dec 06 '16 15:12 antonybudianto

Dear Angular team, maybe it's not obvious, but it's a very dangerous bug - when users can't build production build, it means development of their projects is stopped. And it's not so easy to explain to product owners why it's impossible (for now) to implement minor changes (even if task is just edit text). And this bug is not even labeled. Please, give some attention to this bug. I understand you have a lot of tasks, but it's really important bug.

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

Here're my dependencies. They seem to be working with no issues

@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@angular/[email protected]
@ngtools/[email protected]
[email protected]

jessezhang91 avatar Dec 06 '16 17:12 jessezhang91

@timosalm And what are those "precise dependency versions" I only updated "angular-cli" to latest and that broke all. Changes here

tarlepp avatar Dec 06 '16 17:12 tarlepp

@tarlepp I've created a separate issue for this issue introduced by angular-cli version 1.0.0-beta.22 : #3426

beeman avatar Dec 06 '16 17:12 beeman

same problem:

angular 2.2.4

"@ngtools/webpack": "1.1.9", "typescript": "^2.0.10", "webpack": "^2.1.0-beta.27"

vascofernandes avatar Dec 06 '16 19:12 vascofernandes

Please check https://github.com/angular/angular-cli/issues/3426#issuecomment-265277988 for a solution.

jkuri avatar Dec 06 '16 21:12 jkuri

I've just today started to work with ngc and am hitting this same error.

I also stripped back my entryModule to the bare minimum.

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 {}

All my @angular/ packages are aligned at version 2.2.4 and I've done my best to update all related webpack and typescript related plugins. There are other packages which may be out of date, but as none of them are imported via my AppModule, I can't see why'd they'd effect the compilers ability to load the AppModule (or at least report a meaningful error).

I've tried both relative and absolute paths for the entryModule.

dwightgunning avatar Dec 06 '16 22:12 dwightgunning

@vascofernandes Instead of "^2.0.10" for typescript, try "2.0.10" exactly. I had it install 2.1.1 for me when I had ^ before.

jessezhang91 avatar Dec 06 '16 22:12 jessezhang91

Hi, I just tried that and and no success, same error.

vascofernandes avatar Dec 07 '16 07:12 vascofernandes

shit, same here with cli "1.0.0-beta.22-1" :(

alvipeo avatar Dec 07 '16 20:12 alvipeo