Error: SampleModule is not an NgModule
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
SampleModuleto theimportsarray - 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.
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! ;)
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.
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 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
@expy try deleting node_modules then:
npm cache clean
npm install
in the project directory.
@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 isn't using SEMVER suppose to prevent exactly that?
@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.
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.
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
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'}
Still run into this error with Angular 4.2.3 . Fix it with very strange @winfinit trick 😄 (angular-cli 1.1.3)
i compiled library with ngc
For me issue is set options "skipMetadataEmit": false in file tsconfig.aot.json
"skipMetadataEmit": false that was it.
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.