Skip to content

@ngtools/webpack complainning about not an NgModule #3157

Closed

Description

@princemaple

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.

Activity

  1. marinho commented on Nov 17, 2016

    @marinho

    @princemaple can you paste your AotPlugin configuration, please?

  2. marinho commented on Nov 17, 2016

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

  3. princemaple commented on Nov 17, 2016

    @princemaple
    Author

    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'
    })
  4. princemaple commented on Nov 17, 2016

    @princemaple
    Author

    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.

  5. marinho commented on Nov 17, 2016

    @marinho

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

  6. janwo commented on Nov 17, 2016

    @janwo

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

  7. princemaple commented on Nov 17, 2016

    @princemaple
    Author

    @marinho thanks for taking a look still!

  8. janwo commented on Nov 17, 2016

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

  9. marinho commented on Nov 18, 2016

    @marinho

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

  10. janwo commented on Nov 18, 2016

    @janwo

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

  11. dhardtke commented on Nov 18, 2016

    @dhardtke

    I have the same problem, see #2667

  12. mashhoodr commented on Nov 22, 2016

    @mashhoodr

    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.

  13. dhardtke commented on Nov 22, 2016

    @dhardtke

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

  14. jessezhang91 commented on Nov 22, 2016

    @jessezhang91

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

  15. zakdances commented on Dec 2, 2016

    @zakdances

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

  16. 43 remaining items

  17. arciisine commented on Jan 9, 2017

    @arciisine

    Angular 2.4.2 just landed which fixed TS 2.1 support. I've successfully built 2.4.2 with typescript 2.1.4 and beta 24 of the cli.

  18. sbley commented on Jan 9, 2017

    @sbley

    @arciisine Which Angular dependency has to be updated to 2.4.2? common, core?

  19. jkuri commented on Jan 9, 2017

    @jkuri
    Contributor

    @sbley compiler-cli at least, preferable all.

  20. sbley commented on Jan 9, 2017

    @sbley

    Yeah, in the end these are peer dependencies. If you update one you gotta update all...

  21. ichent commented on Jan 9, 2017

    @ichent

    @princemaple What do you mean?
    Yesterday I founded an example here https://github.com/blacksonic/angular2-aot-webpack (big thanks to the author). But my roadmap is a little bit different
    And now, I'm using webpack. Here is a part of my webpack.config.
    .....
    {
    test: /.ts$/,
    loaders: env.aot ?
    ['awesome-typescript-loader?tsconfig=./client-code/src/tsconfig.json', 'angular2-template-loader', 'angular2-router-loader?genDir=./client-code/src/aot-compiled/app&aot=true'] :
    ['awesome-typescript-loader?tsconfig=./client-code/src/tsconfig.json', 'angular2-template-loader', 'angular2-router-loader']
    }
    ...

    With 'angular2-router-loader' I can split my bundles.
    Here are my "scripts" from packages.json

    "scripts": {
    "prepublish": "yarn run build",
    "build": "yarn run clean && yarn webpack",
    "build:jit": "yarn run clean && yarn webpack -- --env.production",
    "build:production": "yarn run clean && yarn run compiler:aot && yarn webpack -- --env.aot --env.production",
    "compiler:aot": "ngc -p client-code/src/tsconfig-aot.json",
    "clean": "rimraf client-code/dist/* client-code/src/aot-compiled"
    },

  22. rgiosa commented on Jan 9, 2017

    @rgiosa

    Yeap, this is now working with Typescript 2.1.4!

    angular-cli: 1.0.0-beta.24
    node: 4.4.7
    os: win32 x64
    @angular/common: 2.4.2
    @angular/compiler: 2.4.2
    @angular/core: 2.4.2
    @angular/forms: 2.4.2
    @angular/http: 2.4.2
    @angular/platform-browser: 2.4.2
    @angular/platform-browser-dynamic: 2.4.2
    @angular/router: 3.4.2
    @angular/compiler-cli: 2.4.2
    
  23. princemaple commented on Jan 10, 2017

    @princemaple
    Author

    @ichent thanks for the information about the alternative!

  24. ichent commented on Jan 10, 2017

    @ichent

    @princemaple You are welcome!

  25. larssin commented on Jan 14, 2017

    @larssin

    Look for unwanted node_modules folders...

    I experienced the problem with "AppModule is not an NgModule" after trying to run "./node_modules/.bin/ngc" to build a translated version (the build failed and the app wasn't translated).
    I tried to reinstall, change versions etc. but nothing worked.
    I finally realized that something had created an extra node_modules folder under the src folder. It only contains "@angular" and "rxjs" folders. When I delete this extra node_modules I can build again.
    However I still can't figure out how to use i18n - but that is another problem.

  26. AckerApple commented on May 17, 2017

    @AckerApple

    I had one time forgot to add "typings"="index.d.ts" key to my package.json file. Once I did, I stopped getting Please add @NgModule error

  27. Maloric commented on May 22, 2017

    @Maloric

    In case anyone stumbles across this, in my case it was misconfiguration. I was getting a null is not an NgModule error, which was because my entryModule missed of the name of the module:

        new ngtools.AotPlugin({
            tsConfigPath: './tsconfig.json',
            entryModule: root('src/app/pager') 
        })
    

    became

        new ngtools.AotPlugin({
            tsConfigPath: './tsconfig.json',
            entryModule: root('src/app/pager') + '#PagerComponentModule'
        })
    
  28. pratiksha-chandel commented on Jun 13, 2017

    @pratiksha-chandel

    ng build and ng serve is not working for me .gives error

    ERROR in /home/pratiksha/migration//app/shared/user.service.spec.ts (7,3): Cannot find name 'beforeEach'.

    ERROR in /home/pratiksha/migration/app/shared/user.service.spec.ts (13,3): Cannot find name 'it'.

    ERROR in /home/pratiksha/migration/app/shared/user.service.spec.ts (14,5): Cannot find name 'expect'.

    ERROR in PopoverModule is not an NgModule

    ERROR in multi ./src/styles.css ./src/css/main.css ./src/css/font-awesome.min.css ./src/css/daterangepicker.css ./src/css/style.css ./src/css/style-bootstrap.css ./src/css/style-default.css ./src/css/style-material.css
    Module not found: Error: Can't resolve '/home/pratiksha/migration/src/css/main.css' in '/home/pratiksha/migration/node_modules/@angular/cli/models/webpack-configs'
    @ multi ./src/styles.css ./src/css/main.css ./src/css/font-awesome.min.css ./src/css/daterangepicker.css ./src/css/style.css ./src/css/style-bootstrap.css ./src/css/style-default.css ./src/css/style-material.css

    try all but not working for me .
    angular cli is not working after upgrade -this is not supporting to .spec.ts file .
    why this is happing ?

  29. angular-automatic-lock-bot commented on Sep 7, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  30. locked and limited conversation to collaborators on Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions