angular-cli: 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
SampleModule
to theimports
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 angular-cli@1.0.0-beta.21
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.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 46
- Comments: 95 (20 by maintainers)
Commits related to this issue
- downgrade angular cli to fix a bug in cli check https://github.com/angular/angular-cli/issues/3426#issuecomment-266870472 — committed to giovannicandido/angular-spa-example by deleted user 8 years ago
- build: change tsconfig.json for build ~> https://github.com/angular/angular-cli/issues/3426#issuecomment-269673735 ~> https://medium.com/@cyrilletuzi/how-to-build-and-publish-an-angular-module-7ad19c... — committed to ng-hal/ng-hal by dherges 7 years ago
Isn’t this exactly the kind of thing Angular CLI is supposed to help with, making sure that all of the versions being installed fit with each other? Seems like a big fail atm.
+1
just ran into this, didnt debug it, but i find it interesting that I am getting this error only after “ng serve”, then if i will modify any file, and web pack reruns, it is not displaying this error anymore
The same error.
angular-cli: beta.24. angular: 2.4.1
Been getting this in a few places. I was convinced it was my code but after trying to give it TS directly and seeing everyone complain here, I’m happy it’s not just me. Probably spent a minimum of 10hrs here 😃 It doesn’t seem to be very debuggable which is my issue. It just says:
X is not an NgModule
and it’s not even possible to see WHY or how it’s even trying to load stuff. I don’t even have the ability to pass in module-resolutions parameters to typescript to try and see what it’s trying to load which makes this a bitch 😦Yeah I can also confirm that updating
angular-cli
to1.0.0-beta.22-1
causes this problem. Any solutions ?@beeman there was a lot of reports of different issues here. It’s extremely hard to follow and I’ll close more of those.
For your original issue;
https://unpkg.com/angular-sample-module@0.1.2/
shows that you’re missing.metadata.json
and use an old version. You’re also usingtypings
, which is not recommended anymore and been replaced by@types/
. Follow this guide for AOT: https://angular.io/docs/ts/latest/cookbook/aot-compiler.html (basically runngc
instead oftsc
to compile your files, with some more options to skip ngfactory generation).Here’s a full guide on how to make Angular2 component library: https://medium.com/@cyrilletuzi/how-to-build-and-publish-an-angular-module-7ad19c0b4464
Cheers!
Same issue on Windows10 x64
Is angular core team supporting this project, because they should. It seems like angular-cli is having a hard time keeping up, shame because it’s a great tool.
I have the same issue as many others in here,but I found a quick workaround until this bug gets fixed - if you have a smaller app like I do,:
It’s a pain in the ***, so hopefully this will be fixed soon.
Cheers
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.I got mine to work by changing
"angular-cli"
to"1.0.0-beta.15"
.Was having different errors but appears to be building and serving now.
edit: My deps:
Getting this error as well now.
Using:
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.
Upgrading to
@angular/compiler-cli@2.4.2
worked for me.(been added to the thread by @mhmo91)
Guys, those using TypeScript 2.1 please note that this is currently not supported because there are issues with TypeScript 2.1 and Angular itself, not just the CLI.
Those still having the issue with TypeScript 2.0 (ideally the default TypeScript and Angular packages that come with Angular CLI beta.24), can you please share a repository containing a simple Angular CLI generated project that has this issue?
Thanks a lot.
"skipMetadataEmit": false
that was it.argh… forgot about the change… nevertheless:
and
runs without this pesky error as well… So as Great Joe from the Church of Joe used to say… Cheers and beers! 😉
Thanks a lot for your detailed reply @hansl, I appreciate it.
I’ll update my components according to the library and post my updated (working) module here as a reference for future visitors.
Thanks for your work on angular-cli!
With angular-cli version 1.0.0-beta.24 I’m still seeing an error:
ERROR in SampleModule is not an NgModule
in the terminal window and my browser console, but at least the app runs, which is an improvement already 👍🏻 .@hansl is this something that will be fixed in angular-cli or do 3rd-party modules need to update something to prevent this error from happening?
With angular-cli beta.24 and typescript 2.1.4 I got the same error, but when downgraded only the typescript to version 2.0.10 the error was gone.
Try building your project using “ng build --aot” and fix any build errors you have then go back to running “ng serve”.
It seems like typescript@2.1.1 is causing the issue. Downgrading to 2.0.10 seems to make it pick up the metadata correctly.
i compiled library with
ngc
For me issue is set options"skipMetadataEmit": false
in file tsconfig.aot.jsonI 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'}
@thekalinga this is how my package.json looks after the upgrade
FYI, it now works with latest Angular and CLI with the following dependencies:
Pushing back the version of
angular-cli
to1.0.0-beta.21
works for me - even with latest versions of Typescript, Angular andcompiler-cli
:Unfortunately upgrading to ngcli beta 24, typescript 2.1.4 and angular to 2.4.2 didn’t solve my problem - still get the “NgSemanticModule is not an NgModule” error.
Any ideas left?
Ok figured it out, at least in our case. We publish the
.module.metadata.json
in ourlib
folder (the transpiled output ofngc
). However the CLI is trying to import stuff fromsrc
. Presumably for tree-shaking reasons.I don’t love having to include generated code mixed up in my source tree TBH. But if I have to I have to 😃
Hello. I have this error today, after I updated angular to 2.4.1. Today I saw many errors, and “AppModule is not an NgModule”, and “cannot read property codegen” and so on. Then I changed my package.json to previous state (worked state), and now I’m getting an error “AppModule is not an NgModule”. A current package.json is { angular: 2.2.3, router: 3.2.3, “@ngtools/webpack”: “1.1.9”, “typescript”: “2.0.10”, “webpack”: “2.1.0-beta.25” }
and this is not working. Changing 2.2.3 to 2.2.4 not solve this problem.
angular-cli 1.0.0-beta.24 and angular 2.4.1.
When I use the ‘default’ keyword to export my module (export default class TheformModule {} )
“ng build --aot” or “ng build”
And Without the ‘default’ keyword “ng build” :
@Meligy Thankkk uuu, i believe it’s up to the owner of the module to look the problem up. Although i must raise a concern to everyone, This module along with others was working fine with previous builds of ng-cli, and now i’m worried that with every update some modules will just stop working, the whole idea behind the new ng2 design patterns is to embrace external modules n components… now this is just a nightmare with each new ng-cli version as some might just stop working!!!
try beta 24. The issue has disappeared for me
@asBrettisay, this worked for me. I was getting this error with ng2-flex-layout. Downgrading from angular-cli@1.0.0-beta.22 to angular-cli@1.0.0-beta.15 did the trick!
@vangorra This is something to do with the thirdparty library. They are not statically analyzable; basically they don’t publish
metadata.json
files which we need to understand their modules or components.We’re working on showing at least a warning and not failing the compilation when that happens.
ng serve
itself blocks because of https://github.com/webpack/webpack/issues/3464, which will be fixed before webpack RC1.