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.
The same error. angular-cli: beta.24. angular: 2.4.1
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.
Any updates on this issue? can anyone clarify if the Issue is related to ng-cli or the third party module? i'm on: "angular-cli": "1.0.0-beta.24", "@angular/compiler-cli": "^2.3.1", "typescript": "^2.0.10", "@angular/common": "^2.3.1",
the dependencies i have that angular-cli complains about are https://github.com/Gbuomprisco/ng2-material-select https://github.com/yuyang041060120/ng2-validation Thanksss
(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.
I have created a rep with the issue, i just created a new project and imported this module to the main app https://github.com/Gbuomprisco/ng2-material-select
here's the rep. https://github.com/mhmo91/ERROR-in-is-not-an-NgModule
thanksss
@mhmo91 That looks like a library problem https://github.com/Gbuomprisco/ng2-material-select/pull/34
@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!!!
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?
I was able to get my app working after fixing previously harmless typescript errors. After fixing my ts errors I still get "X is not an NgModule" but the app still runs.
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"
WARNING in ./src/$$_gendir/app/app.module.ngfactory.ts 609:37 export 'TheformModule' (imported as 'import26') was not found in '../../app/theform/theform.module'
WARNING in ./src/$$_gendir/app/app.module.ngfactory.ts 696:23 export 'TheformModule' (imported as 'import26') was not found in '../../app/theform/theform.module'
ERROR in default is not an NgModule
And Without the 'default' keyword "ng build" :
ERROR in default is not an NgModule
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.
@hansl can you link the other issue you mentioned is tracking this problem?
Hi guys, I also met this issue, while my SampleModule is literally irrelevant to the HerosModule(see below).
I have code like below within routing module: ex:
loadChildren: 'wrong_path/app/heros/heros.module#HerosModule'
after remove the wrong_path above, everything just fine again.
A little bit more information.
angular 2.2.4
With "@ngtools/webpack": "1.2.1", typescript 2.0.10
I'm getting "ERROR in Cannot read property 'codeGen' of undefined"
With "@ngtools/webpack": "1.1.6", typescript 2.0.10
I'm getting "Error: IndexModule?sync=true is not an NgModule"
With "@ngtools/webpack": "1.1.9", typescript 2.0.10
I'm getting "Error: AppModule is not an NgModule"
angular 2.3.1
With "@ngtools/webpack": "1.1.9", typescript 2.0.10
I'm getting "TypeError: ngCompiler.ReflectorHost is not a constructor"
With "@ngtools/webpack": "1.1.6", typescript 2.0.10
I'm getting "TypeError: ngCompiler.ReflectorHost is not a constructor"
What error do you like? ))) One moment. A building not for production is ok, only aot-compilation is ok, but a final building with aot for production is not ok.
People are seeing this with my lib - ng2-redux - as well. I have reproduced it with CLI beta.24:
Relevant dependencies from package.json:
"@angular/common": "^2.3.1",
"@angular/compiler": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/forms": "^2.3.1",
"@angular/http": "^2.3.1",
"@angular/platform-browser": "^2.3.1",
"@angular/platform-browser-dynamic": "^2.3.1",
"@angular/router": "^3.3.1",
"ng2-redux": "^5.0.0-beta.0",
// ...
"typescript": "~2.0.3"
@hansl I saw your comment above re: 3rd-party libs needing to publish ng module meta data. However we are publishing it:
(that's a screenshot of my lib, as installed in a CLI-generated project's node_modules folder).
Where can I get more info on how to publish an ngmodule correctly?
Here's a repo that reproduces the issue: https://github.com/SethDavenport/redux-cli-test
Ok figured it out, at least in our case. We publish the .module.metadata.json in our lib folder (the transpiled output of ngc). However the CLI is trying to import stuff from src. 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 :)
Same issue. angular-cli 1.0.0-beta24 / typescript 2.1.4 is failing.
"dependencies": { "@angular/common": "^2.4.1", "@angular/compiler": "^2.4.1", "@angular/core": "^2.4.1", "@angular/forms": "^2.4.1", "@angular/http": "^2.4.1", "@angular/platform-browser": "^2.4.1", "@angular/platform-browser-dynamic": "^2.4.1", "@angular/router": "^3.4.1", "core-js": "^2.4.1", "rxjs": "^5.0.1", "ts-helpers": "^1.1.1", "zone.js": "^0.7.2" }, "devDependencies": { "@angular/compiler-cli": "^2.4.1", "@types/jasmine": "2.5.38", "@types/node": "^6.0.42", "angular-cli": "1.0.0-beta.24", "codelyzer": "~2.0.0-beta.1", "jasmine-core": "2.5.2", "jasmine-spec-reporter": "2.5.0", "karma": "1.2.0", "karma-chrome-launcher": "^2.0.0", "karma-cli": "^1.0.1", "karma-jasmine": "^1.0.2", "karma-remap-istanbul": "^0.2.1", "protractor": "~4.0.13", "ts-node": "1.2.1", "tslint": "^4.0.2", "typescript": "^2.1.4" }
I just want to say that @angular/compiler-cli is NOT compatible with TS 2.1. The CLI itself is compatible and will work fine with TS 2.1, but since we use @angular/compiler-cli it won't work.
Refer to https://github.com/angular/angular/pull/13294 for more information. Closing this as nothing needs to be done by Angular CLI.
@hansl I'm amazed to see the story closed for this reason as it's full of people having the same issue, also using supported versions of typescript.
If third party modules need upgrading could you please share some information on what needs to be done? Or a direction where to look? I'm happy to write some tutorial on how to make this error go away as it's in all of my current projects but I have no clue what the actual issue is.
Thanks for considering.