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.
@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/[email protected]/ shows that you're missing .metadata.json and use an old version. You're also using typings, 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 run ngc instead of tsc 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!
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!
Big thanks @hansl for your answer.
- I use @types instaed of typings.
- I use ngc instead of tsc. Here is my package.json
{ "name": "", "version": "1.9.56", "dependencies": { "@angular/common": "2.2.4", "@angular/compiler": "2.2.4", "@angular/compiler-cli": "2.2.4", "@angular/core": "2.2.4", "@angular/forms": "2.2.4", "@angular/http": "2.2.4", "@angular/platform-browser": "2.2.4", "@angular/platform-browser-dynamic": "2.2.4", "@angular/platform-server": "2.2.4", "@angular/router": "3.2.4", "core-js": "^2.4.1", "intl": "^1.1.0", "lodash": "4.17.2", "reflect-metadata": "^0.1.2", "rxjs": "5.0.0-beta.12", "zone.js": "^0.7.2" }, "devDependencies": { "@ngtools/webpack": "1.1.9", "@types/lodash": "4.14.42", "@types/requirejs": "^2.1.28", "angular2-router-loader": "^0.3.3", "angular2-template-loader": "^0.6.0", "awesome-typescript-loader": "^2.2.4", "compression-webpack-plugin": "^0.3.1", "css-loader": "^0.26.1", "extract-text-webpack-plugin": "^2.0.0-beta.4", "file-loader": "^0.9.0", "html-minify-loader": "^1.1.0", "raw-loader": "^0.5.1", "rimraf": "^2.5.4", "style-loader": "^0.13.1", "typescript": "2.0.10", "webpack": "2.1.0-beta.25" }, "scripts": { "prepublish": "yarn run build", "build": "yarn run clean && yarn webpack", "build:jit": "yarn run clean && yarn webpack -- --env.production", "build:production": "yarn run clean && yarn run compiler:aot && yarn webpack -- --env.aot --env.production", "compiler:aot": "ngc -p client-code/src/tsconfig-aot.json", "clean": "rimraf client-code/dist/* client-code/src/aot-compiled" }, "engines": { "node": ">=6.1.0" } } I try to change versions, but it doesn't work. I get different errors. This happened some times ago after updating. yarn run build - ok yarn compiler:aot - ok yarn build:jit - ok yarn build:production - not ok.
So, or with @ngtools/webpack problem, or with angular2-router-loader (angular2-router-loader works without aot)
I have the same issue with this setup.
"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/material": "^2.0.0-beta.1", "@angular/platform-browser": "^2.3.1", "@angular/platform-browser-dynamic": "^2.3.1", "@angular/router": "^3.3.1", "core-js": "^2.4.1", "ng2-material-select": "^0.1.4", "rxjs": "^5.0.1", "ts-helpers": "^1.1.1", "zone.js": "^0.7.2" }, "devDependencies": { "@angular/compiler-cli": "^2.3.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.0.3" }
Upgrading to @angular/[email protected] worked for me.
Hmm still can't understand why this is closed down - going to try @PierreDuc solution tomorrow to fix this.
Using ngcli beta 24 and created new project (5 days ago). Today, upgraded TSC to 2.14 matching my system version. Got error '... is not an NGModule' on ng serve. Upgraded all angular components from 2.31 to 2.42 Module builds, no more error, when running ng serve
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?
Hello. I tired to solve this problem. Yesterday I founded an example here https://github.com/blacksonic/angular2-aot-webpack (big thanks to the author). Today I removed @ngtools/webpack from my project and now I'm using webpack for AoT. I'm happy. Thanks to all.
Pushing back the version of angular-cli to 1.0.0-beta.21 works for me - even with latest versions of Typescript, Angular and compiler-cli:
"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/platform-browser": "2.4.2",
"@angular/platform-browser-dynamic": "2.4.2",
"@angular/router": "3.4.2",
"angular2-jwt": "^0.1.28",
"core-js": "^2.4.1",
"d3": "^4.4.1",
"jquery": "^3.1.1",
"lodash": "^4.17.4",
"ng2-toasty": "^2.2.2",
"rxjs": "^5.0.3",
"semantic-ui": "^2.2.7",
"ts-helpers": "^1.1.2",
"zone.js": "^0.7.4"
},
"devDependencies": {
"@angular/compiler-cli": "2.4.2",
"@types/d3": "^4.4.0",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.21",
"awesome-typescript-loader": "3.0.0-beta.17",
"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",
"webdriver-manager": "10.2.5"
}
Just tried with the latest release angular-cli: 1.0.0-beta.25.5 and it's not working. Reverting back to 21 for now.
Personally I found a way to make this work on my project, basically I did following:
- Update all dependencies
- Then I compared all my files against https://github.com/angular/angular-cli/tree/master/packages/angular-cli/blueprints/ng2/files
- Make necessary changes to
commonfiles
And after this all worked. And below is my current package.json
{
"name": "angular-cli-frontend",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "ng serve --host 0.0.0.0",
"lint": "tslint -t stylish \"src/**/*.ts\"",
"test": "ng test --lint --code-coverage",
"pree2e": "webdriver-manager update",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "2.4.3",
"@angular/compiler": "2.4.3",
"@angular/core": "2.4.3",
"@angular/forms": "2.4.3",
"@angular/http": "2.4.3",
"@angular/material": "2.0.0-beta.1",
"@angular/platform-browser": "2.4.3",
"@angular/platform-browser-dynamic": "2.4.3",
"@angular/router": "3.4.3",
"angular2-jwt": "0.1.28",
"angular2-moment": "1.1.0",
"core-js": "2.4.1",
"hammerjs": "2.0.8",
"ng2-webstorage": "1.5.0",
"rxjs": "5.0.3",
"ts-helpers": "1.1.2",
"zone.js": "0.7.5"
},
"devDependencies": {
"@angular/compiler-cli": "2.4.3",
"@types/jasmine": "2.5.40",
"@types/node": "7.0.0",
"angular-cli": "1.0.0-beta.25.5",
"codelyzer": "2.0.0-beta.4",
"enhanced-resolve": "3.0.3",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "3.1.0",
"karma": "1.3.0",
"karma-chrome-launcher": "2.0.0",
"karma-cli": "1.0.1",
"karma-jasmine": "1.1.0",
"karma-mocha-reporter": "2.2.1",
"karma-phantomjs-launcher": "1.0.2",
"karma-remap-istanbul": "0.4.0",
"protractor": "5.0.0",
"ts-node": "2.0.0",
"tslint": "4.3.1",
"typescript": "2.1.5"
}
}
FYI, it now works with latest Angular and CLI with the following dependencies:
"dependencies": {
"@angular/common": "2.4.4",
"@angular/compiler": "2.4.4",
"@angular/core": "2.4.4",
"@angular/forms": "2.4.4",
"@angular/http": "2.4.4",
"@angular/platform-browser": "2.4.4",
"@angular/platform-browser-dynamic": "2.4.4",
"@angular/router": "3.4.4",
"angular2-jwt": "^0.1.28",
"core-js": "^2.4.1",
"d3": "^4.4.2",
"jquery": "^3.1.1",
"lodash": "^4.17.4",
"ng2-toasty": "^2.2.2",
"rxjs": "^5.0.3",
"semantic-ui": "^2.2.7",
"ts-helpers": "^1.1.2",
"zone.js": "^0.7.6"
},
"devDependencies": {
"@angular/compiler-cli": "2.4.4",
"@types/d3": "^4.4.1",
"@types/jasmine": "2.5.41",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.26",
"awesome-typescript-loader": "3.0.0-beta.18",
"codelyzer": "~2.0.0-beta.4",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "3.2.0",
"karma": "1.4.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.1.0",
"karma-remap-istanbul": "^0.4.0",
"protractor": "~5.0.0",
"ts-node": "2.0.0",
"tslint": "^4.3.1",
"typescript": "~2.1.5",
"webdriver-manager": "11.1.1"
}
I had the same problem but I wasnt able to downgrade typescript or angular-cli because in OS X it worked but if I downgrade in Windows doesn't work anymore, so I just instaled NCU npm i -g npm-check-updatesand did an upgrade of all the package.json and the problem were solved for both OS.
@CanKer Whats the angular version you have after the upgrade?
When I did yarn upgrade, I got 2.3.1 instead of 2.4.4
@thekalinga this is how my package.json looks after the upgrade
"dependencies": {
"@angular/common": "~2.4.4",
"@angular/compiler": "~2.4.4",
"@angular/core": "~2.4.4",
"@angular/forms": "~2.4.4",
"@angular/http": "~2.4.4",
"@angular/platform-browser": "~2.4.4",
"@angular/platform-browser-dynamic": "~2.4.4",
"@angular/router": "~3.4.4",
"core-js": "^2.4.1",
"ng2-date-picker": "^0.2.1",
"ng2-file-upload": "^1.2.0",
"ng2-smart-table": "^0.5.0",
"rxjs": "5.0.3",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.6"
},
"devDependencies": {
"@angular/compiler-cli": "^2.3.1",
"@types/jasmine": "^2.2.30",
"@types/node": "^7.0.3",
"angular-2-dropdown-multiselect": "^0.4.0",
"angular-cli": "1.0.0-beta.19-3",
"codelyzer": "2.0.0-beta.4",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "3.2.0",
"karma": "1.4.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.4.0",
"protractor": "5.0.0",
"ts-node": "2.0.0",
"tslint": "4.3.1",
"typescript": "latest",
"awesome-typescript-loader": "latest",
"webdriver-manager": "11.1.1"
}```
@CanKer Are you sure your using "angular-cli": "1.0.0-beta.19-3". I'm still having the "Error in X is not an NgModule from an npm linked module. But i'm using the latest CLI.
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
** NG Live Development Server is running on http://localhost:4200. **
Hash: 49cd7d49bb76b083774c
Time: 9923ms
chunk {0} polyfills.bundle.js, polyfills.bundle.map (polyfills) 222 kB {4} [initial] [rendered]
chunk {1} main.bundle.js, main.bundle.map (main) 15.6 kB {3} [initial] [rendered]
chunk {2} styles.bundle.js, styles.bundle.map (styles) 10 kB {4} [initial] [rendered]
chunk {3} vendor.bundle.js, vendor.bundle.map (vendor) 2.71 MB [initial] [rendered]
chunk {4} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered]
ERROR in NgSemanticModule is not an NgModule
webpack: Failed to compile.
webpack: Compiling...
Hash: 8d508c11672b2c20762a
Time: 1783ms
chunk {0} polyfills.bundle.js, polyfills.bundle.map (polyfills) 222 kB {4} [initial]
chunk {1} main.bundle.js, main.bundle.map (main) 15.6 kB {3} [initial]
chunk {2} styles.bundle.js, styles.bundle.map (styles) 10 kB {4} [initial]
chunk {3} vendor.bundle.js, vendor.bundle.map (vendor) 2.71 MB [initial]
chunk {4} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry]
webpack: Compiled successfully.
well, today upgraded myself blindly, to:
$ ng -v
angular-cli: 1.0.0-beta.28.3
node: 7.2.1
os: win32 x64
@angular/common: 2.4.7
@angular/compiler: 2.4.7
@angular/core: 2.4.7
@angular/forms: 2.4.7
@angular/http: 2.4.7
@angular/platform-browser: 2.4.7
@angular/platform-browser-dynamic: 2.4.7
@angular/router: 3.4.7`
and
$ tsc -v
Version 2.1.6
I don't see this error anymore... so (at least in my case) it helped... without checking, whatever you guys did: thanks! ;)
@zawor for your information,the latest release is beta 32 and is available under the @angular/cli name, angular-cli will soon be deprecated. :)
Great to hear that your issue is fixed btw