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

Yep, just got bit by this after upgrading typescript to 2.1.4, had to revert back to 2.0.1, which is a bummer, because 2.1.4 has async/await support for es5

avatsaev avatar Dec 11 '16 21:12 avatsaev

Also need this.

lygstate avatar Dec 12 '16 10:12 lygstate

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.

mischkl avatar Dec 12 '16 14:12 mischkl

Just a sec ago switched Ubuntu to Win10 and made a ng serve on same source. To my surprise this dragon jumped out of the bushes to bite my arse. On Ubuntu 16.10 it works like a charm. What is more, I have not noticed anyone here from any Linux distro (or no one managed to state it clear enough). So probably it is somehow platform dependent. How? don't know... :P

My setup is pretty much ToH based. Running on:

node: 7.2.1
ng: 2.2.3
ts: 2.1.4
ng-cli: 1.0.0-beta.22-1

zawor avatar Dec 12 '16 15:12 zawor

@filipesilva or @hansl - is this something to do with angular-cli or with each of the projects themselves? Two example external deps which are giving this error for me are:

  • https://github.com/apollostack/angular2-apollo
  • https://github.com/yuyang041060120/ng2-validation

Would be nice to get your insight to if this is possible to fix in the next version as it's quite painful at the moment :)

intellix avatar Dec 12 '16 15:12 intellix

I'm running in Ubuntu 16.04 and recurved the same error. I followed the suggestion above and use typescript 2.0.10 for now. It's a good work around. That being said, I'm also using Apollo client although I fail to see how that is relevant.

On Mon, Dec 12, 2016, 7:16 AM Dominic Watson [email protected] wrote:

@filipesilva https://github.com/filipesilva or @hansl https://github.com/hansl - is this something to do with angular-cli or with each of the projects themselves? Two example external deps which are giving this error for me are:

  • https://github.com/apollostack/angular2-apollo
  • https://github.com/yuyang041060120/ng2-validation

Would be nice to get your insight to if this is possible to fix in the next version as it's quite painful at the moment :)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/3426#issuecomment-266456577, or mute the thread https://github.com/notifications/unsubscribe-auth/ABq9MsqmBykpUW2GIb1_PfrN-4TIFnZhks5rHWU3gaJpZM4LFF9D .

vangorra avatar Dec 12 '16 15:12 vangorra

ok my bad... sorry for confusion... double checked the versions... Ubuntu was running on outdated typescript 2.0.10 not 2.1.4 but Win had fresh 2.1.4. Now they are in sync and both fail in exact same manner...

zawor avatar Dec 12 '16 15:12 zawor

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.

avatsaev avatar Dec 12 '16 20:12 avatsaev

@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.

hansl avatar Dec 12 '16 20:12 hansl

This is a dupe of another issue here that we use for tracking. I'll close this one when I find it (it's somewhere in my inbox).

hansl avatar Dec 12 '16 20:12 hansl

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,:

  • try identifying the module which is not getting compiled,
  • comment it out in the @ngModule,
  • do the ng serve
  • if it passes the build, remove the comment on live, and it works..

It's a pain in the ***, so hopefully this will be fixed soon.

Cheers

brtka avatar Dec 13 '16 10:12 brtka

+1

jlabaj avatar Dec 13 '16 13:12 jlabaj

Have the same issue. Temporarily workaround that works for me is to downgrade typescript to 2.0.10.

ppopadiyn avatar Dec 13 '16 19:12 ppopadiyn

I'm creating third party libraries that expose NgModules. I simple build publish to npm and import the modules

I can confirm that downgrade to 1.0.0-beta.21 fix the issue

giovannicandido avatar Dec 13 '16 19:12 giovannicandido

In my project I have used typescript 2.0.10 all the way long, so "downgrade" to that version is not the solution.

tarlepp avatar Dec 13 '16 21:12 tarlepp

Ok, so just tested downgrading the ng cli to two different versions, with no luck, Any ideas?

brtka avatar Dec 14 '16 19:12 brtka

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:

  "dependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
    "@angular/platform-browser": "2.0.0",
    "@angular/platform-browser-dynamic": "2.0.0",
    "@angular/router": "3.0.0",
    "angular-cli": "1.0.0-beta.15",
    "body-parser": "1.15.2",
    "cookie-parser": "^1.4.3",
    "core-js": "2.4.1",
    "immutable": "^3.8.1",
    "jsonwebtoken": "7.1.9",
    "lodash": "4.17.2",
    "moment": "^2.15.2",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@types/jasmine": "^2.2.30",
    "ava": "^0.17.0",
    "codelyzer": "~0.0.26",
    "jasmine-core": "2.4.1",
    "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.5",
    "supertest": "^2.0.1",
    "ts-node": "1.2.1",
    "typescript": "2.0.2",
    "webpack": "^2.1.0-beta.22"
  }

asBrettisay avatar Dec 14 '16 20:12 asBrettisay

@asBrettisay, this worked for me. I was getting this error with ng2-flex-layout. Downgrading from [email protected] to [email protected] did the trick!

jmccannster avatar Dec 16 '16 16:12 jmccannster

Just ran into this on a fresh project. "angular-cli": "1.0.0-beta.22-1"

10% building modules 2/2 modules 0 activeError: AppModule is not an NgModule

Downgrading back to "angular-cli": "1.0.0-beta.20-4" fixed the issue for me.

benjamincharity avatar Dec 19 '16 16:12 benjamincharity

try beta 24. The issue has disappeared for me

the-destro avatar Dec 21 '16 18:12 the-destro