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

Error: SampleModule is not an NgModule

Open beeman opened this issue 9 years ago • 95 comments

OS?

macOS Sierra

Versions.

angular-cli: 1.0.0-beta.22
node: 7.2.0
os: darwin x64

Repro steps.

1. Scaffold new app:

$ ng new angular-sample-app --skip-git --skip-npm --style=scss --inline-template
$ cd angular-sample-app
$ yarn
$ git init
$ git add .
$ git commit -am "Initial commit"

2. Add dependency to angular-sample-module

This source to this module can be found here, and it's available on npmjs.

$ yarn add angular-sample-module

3. Add new module to AppModule

  • Edit src/app/app.module.ts
  • Add dependency: import { SampleModule } from 'angular-sample-module';
  • Add SampleModule to the imports array
  • Edit src/app/app.component.ts
  • Add <sampleComponent></sampleComponent> to the template

4. Start ng serve

$ ng serve
** NG Live Development Server is running on http://localhost:4200. **
 10% building modules 2/2 modules 0 active(node:18364) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: SampleModule is not an NgModule
(node:18364) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
 20% building modules 84/84 modules 0 active

The log given by the failure.

(node:17462) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: SampleModule is not an NgModule
(node:17462) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Mention any other details that might be useful.

Downgrading to the previous version of angular-cli makes it work:

$ npm install --save-dev [email protected]

Link to a sample app showing the issue: https://github.com/beeman/angular-sample-app

Using ng new angular-sample-app without my custom parameters on version 1.0.0-beta.22 and npm install over yarn add yields the same results.

beeman avatar Dec 06 '16 07:12 beeman

argh... forgot about the change... nevertheless:

$ ng -v
@angular/cli: 1.0.0-beta.32.3 [1.0.0-beta.24]
node: 7.2.1
os: win32 x64
@angular/common: 2.4.7
@angular/compiler: 2.4.7
@angular/core: 2.4.7
@angular/forms: 2.4.7
@angular/http: 2.4.7
@angular/platform-browser: 2.4.7
@angular/platform-browser-dynamic: 2.4.7
@angular/router: 3.4.7
@angular/compiler-cli: 2.4.7
@angular/cli: 1.0.0-beta.32.3

and

$ nr serve

runs without this pesky error as well... So as Great Joe from the Church of Joe used to say... Cheers and beers! ;)

zawor avatar Feb 18 '17 00:02 zawor

Currently have this issue with:

    "@angular/common": "^2.4.8",
    "@angular/compiler": "^2.4.8",
    "@angular/core": "^2.4.8",
    "@angular/forms": "^2.4.8",
    "@angular/http": "^2.4.8",
    "@angular/platform-browser": "^2.4.8",
    "@angular/platform-browser-dynamic": "^2.4.8",
    "@angular/platform-server": "2.4.8",
    "@angular/router": "^3.4.8",
    "@angular/cli": "1.0.0-beta.32.3",
    "@angular/compiler-cli": "^2.4.8",
    "typescript": "^2.1.6"

ng serve works, but both ng build --prod and ng build --prod --no-aot fail

I have also tried this with angular 2.4.0 and typescripts, (2.0.10, 2.1.0)

Err, found my error. My loadChildren module started with a downcase when it needed to be upcase.

jrothrock avatar Feb 21 '17 00:02 jrothrock

Getting this error as well now.

Using:

@angular/cli: 1.0.0-rc.0 node: 7.2.1 os: darwin x64 @angular/common: 2.4.8 @angular/compiler: 2.4.8 @angular/core: 2.4.8 @angular/forms: 2.4.8 @angular/http: 2.4.8 @angular/platform-browser: 2.4.8 @angular/platform-browser-dynamic: 2.4.8 @angular/router: 3.4.7 @angular/cli: 1.0.0-rc.0 @angular/compiler-cli: 2.4.8

Also, this error occurs even when running "ng serve", however, after the initial error, when I make changes to the code and save, the code does compile properly and runs. This error only occurs on first run of "ng serve".

Finally, cannot perform "ng build --prod" because of this error.

expy avatar Feb 28 '17 13:02 expy

@expy I had it as well, I just updated from BETA to RC. After running an ng build --aot I was able to run ng serve again.

@angular/cli: 1.0.0-rc.0 node: 6.9.1 os: darwin x64 @angular/cli: 1.0.0-rc.0 @angular/common: 2.4.8 @angular/compiler: 2.4.8 @angular/core: 2.4.8 @angular/forms: 2.4.8 @angular/http: 2.4.8 @angular/material: 2.0.0-beta.2 @angular/platform-browser: 2.4.8 @angular/platform-browser-dynamic: 2.4.8 @angular/router: 3.4.8 @angular/compiler-cli: 2.4.8

0x1ad2 avatar Feb 28 '17 14:02 0x1ad2

@expy try deleting node_modules then:

npm cache clean
npm install

in the project directory.

Meligy avatar Feb 28 '17 14:02 Meligy

@0x1ad2 @Meligy I've tried the above, the problem may lie in a Module that isn't up-to-date with the latest Angular2 / Angular-Cli changes.

I've contacted the owner of the Module for more information.

Thanks for you assistance.

expy avatar Feb 28 '17 14:02 expy

@expy isn't using SEMVER suppose to prevent exactly that?

SylTi avatar Feb 28 '17 14:02 SylTi

@SylTi that Module is tested and working on @angular v2.4.1. I upgraded my modules and cli yesterday and this was the only issue.

expy avatar Feb 28 '17 15:02 expy

Please see ERROR in PasswordStrengthBarModule is not an NgModule.

The interesting twist here is that ng serve initially fails with this error, but a rebuild is successful! This is reproducible and is not resolved with the different typescript/angular-cli versions mentioned in this thread.

rnadler avatar Mar 11 '17 22:03 rnadler

Been experiencing this issue in a npm package I am working on and finally managed to fix it by AOT compilation using the ngc compiler.

https://angular.io/docs/ts/latest/cookbook/aot-compiler.html#!#compile

evansmwendwa avatar Mar 11 '17 22:03 evansmwendwa

I was able to resolve this error by modifying my app.routes. I removed the hashtag reference to internal components on loadChildren routes.

{ path: '/modules', loadChildren: 'app/modules/modules.module#ModulesComponent'} TO { path: '/modules', loadChildren: 'app/modules/modules.module'}

bentbot avatar Jun 05 '17 23:06 bentbot

Still run into this error with Angular 4.2.3 . Fix it with very strange @winfinit trick 😄 (angular-cli 1.1.3)

maximelafarie avatar Jun 22 '17 08:06 maximelafarie

i compiled library with ngc For me issue is set options "skipMetadataEmit": false in file tsconfig.aot.json

kkaabbaa avatar Jun 28 '17 15:06 kkaabbaa

"skipMetadataEmit": false that was it.

yogeshgadge avatar Aug 03 '17 18:08 yogeshgadge

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.