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.
Same issue on Windows10 x64
Yeah I can also confirm that updating angular-cli to 1.0.0-beta.22-1 causes this problem. Any solutions ?
+1
same here
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 :(
Had same issue with this and it is related to incompatibility of Angular versions between 2.2.* and
previous versions, so; update https://github.com/beeman/angular-sample-module/blob/master/package.json#L32-L33 to 2.2.3 which you have in your project and this will get compiled.
Summary is that 3rd party libs package.json should have same version of Angular than your project.
I'm getting this error with 2.2.3 having already been set.
I tried with an example project that @beeman man provided here and updated package.json in https://github.com/beeman/angular-sample-module and it got compiled.
spend a lot of time too some week ago on real world app and this solved the issue too.
Interesting. I just installed the latest version of Angular-Cli from Github, and was able to serve the included app. I changed core and common, and received the same error message. After replacing the entire contents with the beeman's sample, and updating core and common versions, I get "must be inside an angular-cli project to use build..." Changing a few parameters to make it more general in it's operation, and removing the main: and typings: declarations didn't help... Anyone have an idea of what's causing this? I'm using node 4.x.x. Thanks.
Hello, same issue with 1.0.0-beta.22 on macOS Sierra. And it works fine on 1.0.0-beta.21
Same thing happened to me 1.0.0-beta.22
It seems like [email protected] is causing the issue. Downgrading to 2.0.10 seems to make it pick up the metadata correctly.
@lurock I encountered this bug running on TypeScript version 2.0.10:
~/workspace/beeman/angular-sample-app master
❯ grep version node_modules/typescript/package.json
"version": "2.0.10",
~/workspace/beeman/angular-sample-app master
❯ tsc -v
Version 2.0.10
Tried to use 2.0.10, to no avail...
Get Outlook for Androidhttps://aka.ms/ghei36
On Wed, Dec 7, 2016 at 4:50 PM -0600, "Bram Borggreve" <[email protected]mailto:[email protected]> wrote:
@lurockhttps://github.com/lurock I encountered this bug running on TypeScript version 2.0.10:
~/workspace/beeman/angular-sample-app master ? grep version node_modules/typescript/package.json "version": "2.0.10",
~/workspace/beeman/angular-sample-app master ? tsc -v Version 2.0.10
You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/angular/angular-cli/issues/3426#issuecomment-265599086, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJTUJDxsGt_RMrdJtadUyFhJogwsN-Osks5rFzhMgaJpZM4LFF9D.
Try building your project using "ng build --aot" and fix any build errors you have then go back to running "ng serve".
This gives me very similar output.
ng build --aot
10% building modules 2/2 modules 0 activeUnexpected value 'SampleModule' imported by the module 'AppModule'
Error: Unexpected value 'SampleModule' imported by the module 'AppModule'
at /Users/beeman/workspace/beeman/angular-sample-app/node_modules/@angular/compiler/bundles/compiler.umd.js:14675:33
at Array.forEach (native)
at CompileMetadataResolver._loadNgModuleMetadata (/Users/beeman/workspace/beeman/angular-sample-app/node_modules/@angular/compiler/bundles/compiler.umd.js:14660:51)
at CompileMetadataResolver.getUnloadedNgModuleMetadata (/Users/beeman/workspace/beeman/angular-sample-app/node_modules/@angular/compiler/bundles/compiler.umd.js:14636:23)
at addNgModule (/Users/beeman/workspace/beeman/angular-sample-app/node_modules/@angular/compiler/bundles/compiler.umd.js:12944:43)
at /Users/beeman/workspace/beeman/angular-sample-app/node_modules/@angular/compiler/bundles/compiler.umd.js:12957:16
at Array.forEach (native)
at _createNgModules (/Users/beeman/workspace/beeman/angular-sample-app/node_modules/@angular/compiler/bundles/compiler.umd.js:12956:28)
at analyzeNgModules (/Users/beeman/workspace/beeman/angular-sample-app/node_modules/@angular/compiler/bundles/compiler.umd.js:12700:16)
at analyzeAndValidateNgModules (/Users/beeman/workspace/beeman/angular-sample-app/node_modules/@angular/compiler/bundles/compiler.umd.js:12704:20)
at OfflineCompiler.compileModules (/Users/beeman/workspace/beeman/angular-sample-app/node_modules/@angular/compiler/bundles/compiler.umd.js:12775:20)
at CodeGenerator.codegen (/Users/beeman/workspace/beeman/angular-sample-app/node_modules/@angular/compiler-cli/src/codegen.js:58:30)
at /Users/beeman/workspace/beeman/angular-sample-app/node_modules/@ngtools/webpack/src/plugin.js:210:73
at process._tickCallback (internal/process/next_tick.js:103:7)
Hi everyone,
It has been taking me days to get a 'production' build, cause of all kind of error..
Some are typescript 2.1.1 related, some Angular 2.2.4 and some to the fact of AOT compiling.
Please also take in mind, when building a production build with --aot.. That export default doesn't work!
https://github.com/angular/angular/issues/11402
You can use all the latest versions of everything, and than not use --aot, made it work for me.
Having the same issue after updating a project from Angular CLI 1.0.0-beta.19-3 to the latest (1.0.0-beta.22-1) on macOS Sierra. It appears that the following line is no longer returning anything in node_modules/@ngtools/webpack/src/plugin.js:330:
var ngModules = this._reflector.annotations(staticSymbol).filter(function (s) { return s instanceof core_1.NgModule; });
It looks like the instance of s is not core_1.NgModule.
If I change (monkeypatch) this to the following it works (though probably not the way it should be):
var ngModules = this._reflector.annotations(staticSymbol).filter(function (s) { return s.toString() === "@NgModule" });
Same thing here : https://github.com/yuyang041060120/ng2-validation/issues/28
Downgrading to 1.0.0-beta.21 fix the issue
The same issue. I am trying to start the sample app (full tour of heroes like here: https://embed.plnkr.co/?show=preview) with angular-cli 1.0.0-beta.22-1. When I remove usage of package angular-in-memory-web-api, the application not stuck in building.
"dependencies": { "@angular/common": "2.2.3", "@angular/compiler": "2.2.3", "@angular/core": "2.2.3", "@angular/forms": "2.2.3", "@angular/http": "2.2.3", "@angular/platform-browser": "2.2.3", "@angular/platform-browser-dynamic": "2.2.3", "@angular/router": "3.2.3", "angular-in-memory-web-api": "0.1.16", "core-js": "^2.4.1", "rxjs": "5.0.0-beta.12", "ts-helpers": "^1.1.1", "zone.js": "^0.6.23" }