angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ERROR in ** is not an NgModule

Open Pilukina opened this issue 9 years ago • 10 comments

Please provide us with the following information:

OS?

Windows 7.

Versions.

angular-cli: 1.0.0-beta.28.3 node: 6.9.2 os: win32 x64 @angular/common: 2.4.2 @angular/compiler: 2.4.2 @angular/core: 2.4.2 @angular/forms: 2.4.2 @angular/http: 2.4.2 @angular/material: 2.0.0-beta.1 @angular/platform-browser: 2.4.2 @angular/platform-browser-dynamic: 2.4.2 @angular/router: 3.4.2 @angular/compiler-cli: 2.4.2


### Repro steps.
I'm trying to create a custom component. I've created a HelloWorld simple component based on the follow example:
[]([https://www.npmjs.com/package/angular-sample-module])

**It works successfully when using "angular-cli": "1.0.0-beta.21".** 
I don't like using this CLI version due I have problems including css files on angular-cli.json -> styles:[].
And also the import:@import '~@angular/material/core/theming/prebuilt/deeppurple-amber.css';
it is not recognized. 
Maybe, these are a matters of another issue. 

**The current one that I'm reporting is using the "angular-cli": "1.0.0-beta.28.3".** 


### The log given by the failure.
After compiling in terminal appears `"ERROR in HelloModule is not an  NgModule"`. I cannot load my app on web browser. 

### Mention any other details that might be useful.
The dependencies in my package.json are:

"dependencies": { "@angular/common": "2.4.2", "@angular/compiler": "2.4.2", "@angular/core": "2.4.2", "@angular/forms": "2.4.2", "@angular/http": "2.4.2", "@angular/material": "^2.0.0-beta.0", "@angular/platform-browser": "2.4.2", "@angular/platform-browser-dynamic": "2.4.2", "@angular/router": "3.4.2", "@angular2-material/button": "^2.0.0-alpha.8-2", "@angular2-material/card": "^2.0.0-alpha.8-2", "@angular2-material/checkbox": "^2.0.0-alpha.8-2", "@angular2-material/core": "^2.0.0-alpha.8-2", "@angular2-material/icon": "^2.0.0-alpha.8-2", "@angular2-material/radio": "^2.0.0-alpha.8-2", "@angular2-material/slider": "^2.0.0-alpha.8-2", "@angular2-material/tooltip": "^2.0.0-alpha.8-2", "@types/google-maps": "3.1.28", "angular-sample-module": "^0.1.2", "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.2", "@types/hammerjs": "^2.0.33", "@types/jasmine": "2.5.38", "@types/jszip": "0.0.31", "@types/node": "^6.0.42", "@types/pako": "^0.2.31", "@types/xml2js": "0.0.32", "angular-cli": "1.0.0-beta.28.3", "angular-ide": "^0.9.10", "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.0.10" }

> ---------------------------------------------------------------
> Thanks! We'll be in touch soon.

Pilukina avatar Feb 02 '17 10:02 Pilukina

Please upgrade the CLI version to beta 29, and delete your node_modules folder and run npm install again. See if that helps.

Meligy avatar Feb 02 '17 10:02 Meligy

Is the 'HelloModule' in the app itself or in a library?

Also, you're using an ancient version of angular material. The package name was changed to @angular/material

clydin avatar Feb 02 '17 11:02 clydin

The latest version on npm registry is 1.0.0-beta.28.3. I'd upgrade once 29 It'll be avalaible. Many thanks.

The HelloModule is on a library. Thanks for the info about material.

Pilukina avatar Feb 02 '17 11:02 Pilukina

Is the library installed or linked? Can you list the package.json for the library?

clydin avatar Feb 02 '17 11:02 clydin

@Pilukina Please update your angular-cli with the following commands:

npm uninstall -g angular-cli
npm clear cache
npm install -g @angular/cli

Navigate to your project directory and do the following command:

ng init

RicardoVaranda avatar Feb 02 '17 11:02 RicardoVaranda

Updated the Angular CLI version and re-init the project (basically I've taken the relevant info from angular-cli and package.json created by ng init).

My HelloWorld library is linked due It is still not doing any feature new. Just to be sure I've tested with SampleModule provided here: https://www.npmjs.com/package/angular-sample-module

Still same problem: ERROR in SampleModule is not an NgModule

I'm sure It works with version 21 ("angular-cli": "1.0.0-beta.21"). It could help you to find the bug which happens in all versions after this one.

My package.json dependencies (the full version):

 "dependencies": {
    "@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",
    "@angular/material": "^2.0.0-beta.0",
    "@types/google-maps": "3.1.28",
    "angular-sample-module": "^0.1.2",
    "angular2-highcharts": "^0.3.3",
    "atob": "^2.0.3",
    "bootstrap": "^3.3.7",
    "btoa": "^1.1.2",
    "hammerjs": "^2.0.8",
    "highcharts": "^5.0.0",
    "jszip": "^3.1.3",
    "ng2-bootstrap": "^1.1.16-9",
    "primeng": "^1.0.1",
    "xml2js": "0.4.17",
    "xml2js-es6-promise": "1.1.1",
    "core-js": "^2.4.1",
    "rxjs": "^5.0.1",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.7.2"
  },
  "devDependencies": {
    "@angular/cli": "1.0.0-beta.29",
    "@angular/compiler-cli": "^2.3.1",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "@types/hammerjs": "^2.0.33",
    "@types/jszip": "0.0.31",
    "@types/pako": "^0.2.31",
    "@types/xml2js": "0.0.32",
    "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.3.0",
    "typescript": "~2.0.3"
  }

The package.json of the HelloModule library and the SampleModule library is the same:

>   "dependencies": {},
>   "devDependencies": {
>     "@angular/core": "^2.0.0",
>     "@angular/common": "^2.0.0",
>     "codelyzer": "^0.0.20",
>     "rxjs": "5.0.0-beta.12",
>     "tslint": "^3.15.1",
>     "typescript": "2.0.2",
>     "typings": "^1.0.4",
>     "zone.js": "0.6.23"
>   }

The last test was executed with the follow versions:

@angular/cli: 1.0.0-beta.29 node: 6.9.2 os: win32 x64 @angular/common: 2.4.2 @angular/compiler: 2.4.2 @angular/core: 2.4.2 @angular/forms: 2.4.2 @angular/http: 2.4.2 @angular/platform-browser: 2.4.2 @angular/platform-browser-dynamic: 2.4.2 @angular/router: 3.4.2 @angular/material: 2.0.0-beta.1 @angular/cli: 1.0.0-beta.29 @angular/compiler-cli: 2.4.2

Pilukina avatar Feb 02 '17 13:02 Pilukina

The simple solution is to delete the node_modules directory inside the linked library.

What is happening is that when the library is linked, the angular libraries originating from the dev dependencies are being used. This results in two different sets of angular libraries within one application and generally manifests as the error you are seeing.

clydin avatar Feb 02 '17 14:02 clydin

It works, Thank you so much!

Pilukina avatar Feb 03 '17 08:02 Pilukina

Closing as answered by @clydin. Cheers!

filipesilva avatar Feb 03 '17 15:02 filipesilva

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.