Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error "Please add a @NgModule annotation" in Angular4 #15763

Closed
davidanaya opened this issue Apr 4, 2017 · 70 comments
Closed

Error "Please add a @NgModule annotation" in Angular4 #15763

davidanaya opened this issue Apr 4, 2017 · 70 comments

Comments

@davidanaya
Copy link

I'm submitting a ... (check one with "x")

[X] bug report

Current behavior
I have an Angular application which imports a module from another repository.

So my app.module.ts

@NgModule({
  imports: [
    ...
    MyCommonModule,
  ],
  declarations: [...],
  providers: [...],
  bootstrap: [AppComponent]
})
export class AppModule { }

and then in my node_modules I have my common repository (installed with yarn/npm in package.json) with the file file my-common-module.d.ts

@NgModule({
  imports: [...],
  declarations: [...],
  providers: [...],
  exports: [...]
})
export class MyCommonModule {}

This works fine with Angular 2.
Now, I delete node_modules and change the version of Angular to 4.0 in the package.json of my app and then yarn again.
I build the app with webpack, no errors, and when I run it I get the following error in the browser

Uncaught Error: Unexpected value 'MyCommonModule' imported by the module 'AppModule'. Please add a @NgModule annotation.

Expected behavior
I'd expect this to work the same with Angular4 or Angular2.

My question is, do I need to also upgrade the common module to Angular4 for this to work? I thought that this would already be transpiled to js when I import it in my main app module, maybe I'm wrong.

Please tell us about your environment:
I tested this with webpack-dev-server

  • Angular version: 2.0.X
    With 2.0.0 it's working, with 4.0.0 it's not.

  • Browser:
    I tested this in Chrome and FF.

  • Language:
    I'm using typescript 2.2.2

  • Node (for AoT issues): node --version =

@DzmitryShylovich
Copy link
Contributor

Please add a small reproduction.

@davidanaya
Copy link
Author

I can´t create a plunkr with this setup nor upload this to my git account as it's not open source code. I could try to create another 2 simple repos to reproduce this same scenario, but I'd need to confirm first that I can import a repo generated with Angular 2 from another project in Angular 4. That should not be an issue, right?
Thanks!

@DzmitryShylovich
Copy link
Contributor

but I'd need to confirm first that I can import a repo generated with Angular 2 from another project in Angular 4

yes, it should work without any issue.

is MyCommonModule your own or 3rd party module?

@davidanaya
Copy link
Author

It's my own module. It contains some common components used by different projects.
I wanted to upgrade one of those projects to Angular 4 but without touching the commons one.

@kukjevov
Copy link
Contributor

kukjevov commented Apr 4, 2017

What are your dependencies on your MyCommonModule? How did you specify dependency on angular? It is among dependencies or peerDependecies? Anyway if you have something like this "@angular/core": "^2.4.3" in your "library" and "@angular/core": "^4.0.1" in your application it wont work. NPM creates two versions of angular in your node_modules and if NgModules is defined in 2 files they are not same.

You have to set version in your "library" to "@angular/core": ">=2.4.3" or to "@angular/core": "^4.0.0". You should check subdirectory of your lib in node_modules if there is directory named node_modules and if there is @angular/core.

If it is there, that is the problem. I hope it helps, if not i can explain better :).

@davidanaya
Copy link
Author

davidanaya commented Apr 5, 2017

Thanks @kukjevov so it really is a problem if my library uses Angular 2 and my app uses Angular 4.
The thing is my library in Angular 2 is used by other applications which are in Angular 2 and I can´t migrate them at the moment, so it has to stay in Angular 2.

If I use >=2.4.3 in my library does it mean that it will use Angular 4 when I build my app and Angular 2.4.3 when I use it with my other apps?

@Toxicable thanks for your input, I think that's exactly what's happening.

@robwormald
Copy link
Contributor

Any component written for 2.x should work for 4.x.

It's important that you do not generate the factories in your library code. Your library code should only emit the metadata.json files.

Each application should then import NgModules from the shared library code, and compile each application as a unit.

This is baked into the entire design of angular's compiler - backwards compatibility. This works because the metadata.json is backwards compatible, and ngFactory code can be generated for each version when an app is compiled.

@davidanaya
Copy link
Author

Thanks @robwormald could you please elaborate or give me a hint on where to look for some more info about it? My common module inside node_modules has a my-common-module.d.ts with the exports, including export declare class MyCommonModule {} and then the transpiled contents of the module in js, but I never heard of metadata.json files.

@kukjevov
Copy link
Contributor

kukjevov commented Apr 5, 2017

hi @davidanaya well if you use >=2.4.3 your library might compile with latest angular, but if you use this library that has dependency spefified this way it should work with any version of angular higher than 2.4.3. That means if your application has dependency "@angular/core": "2.4.5" your library should not create its own node_modules with different angular version since it is compatible with version specified in application package.json. Also if your application uses version 4.0.1 it is still in range of >=2.4.3 and it should be fine.

I am not completely sure, but i think this should work as far as your code will be backward compatible. It does not matter if your library is compiled with 2.4.3, or 4.0.1 if code compiles and works with both of them.

@davidanaya
Copy link
Author

Thanks @kukjevov I'll give it a try.

@davidanaya
Copy link
Author

Well, that worked!
Thanks a lot, @kukjevov

So, just to summarize in case someone else needs it.

In my common library I used this in my package.json

 "dependencies": {
    "@angular/core": ">=2.0.0",
    "@angular/common": ">=2.0.0",
    "@angular/router": ">=3.0.0",
    "@angular/http": ">=2.0.0",
    "@angular/platform-browser": ">=2.0.0",

I did this in a different branch, feature/angular4 and run yarn install
When I checked my yarn.lock I saw this was inside:

"@angular/common@>2.0.0":
  version "4.0.1"
  resolved "https://registry.yarnpkg.com/@angular/common/-/common-4.0.1.tgz#df488eada842b2d841ded750712292b18387b5b0"

Looks promising; if I'm not wrong it took the last available version for @angular/common, which is 4.0.1

Now I push the branch to my github repo and change to my app project.

I run yarn upgrade my_guthub_repo/common#feature/angular4
I check my yarn.lock and I have this

"@angular/common@4.0.0", "@angular/common@>2.0.0":
  version "4.0.0"
  resolved "https://registry.npmjs.org/@angular/common/-/common-4.0.0.tgz#ca18983222fdab4ecaa7a8b99eda6ff661e6dc92"

I run it, and it works 👍

@IevhenIkonnykov
Copy link

Hello,
It seems that I have a similar problem, but it looks differently.
I had a project on Angular 2.4.3 that worked fine and then I moved it to Angular 4.0.1. So now I have a problem:

compiler.es5.js:14577 Uncaught Error: Unexpected value 'LoadingComponent' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@component annotation.
at syntaxError (http://localhost:4200/vendor.bundle.js:53165:34) []
at http://localhost:4200/vendor.bundle.js:65680:40 []
at Array.forEach (native) []
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:4200/vendor.bundle.js:65662:54) []
at JitCompiler._loadModules (http://localhost:4200/vendor.bundle.js:76740:64) []
at JitCompiler.compileModuleAndComponents (http://localhost:4200/vendor.bundle.js:76699:52) []
at JitCompiler.compileModuleAsync (http://localhost:4200/vendor.bundle.js:76661:21) []
at PlatformRef
.bootstrapModuleWithZone (http://localhost:4200/vendor.bundle.js:5145:25) []
at PlatformRef
.bootstrapModule (http://localhost:4200/vendor.bundle.js:5131:21) []
at Object.245 (http://localhost:4200/main.bundle.js:16726:124) []
at webpack_require (http://localhost:4200/inline.bundle.js:53:30) []
at Object.778 (http://localhost:4200/main.bundle.js:45437:18) []
at webpack_require (http://localhost:4200/inline.bundle.js:53:30) []
at webpackJsonpCallback (http://localhost:4200/inline.bundle.js:24:23) []

But LoadingComponent is correct:

import {Component, Input} from '@angular/core';
@component({
selector: 'cdp-loading',
templateUrl: './loading.component.html'
})
export class LoadingComponent {
@input() public isBusy: boolean;
}

When I remove this component it complains on another and so on.
My package.json:
{
"name": "web-services-ui",
"version": "0.1.0",
"description": "Angular2 SPA",
"license": "ISC",
"author": "Author",
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.config.json",
"build": "ng build",
"lint": "ng lint",
"test": "ng test",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/platform-server": "^4.0.0",
"@angular/router": "^4.0.0",
"@angular/animations": "^4.0.0",
"core-js": "^2.4.1",
"rxjs": "^5.1.0",
"zone.js": "^0.8.4",
"primeng": "^4.0.0-rc.2",
"marked": "0.3.6",
"prismjs": "^1.6.0"
},
"devDependencies": {
"@angular/cli": "1.0.0",
"@angular/compiler-cli": "^4.0.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-coverage-istanbul-reporter": "^0.2.0",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "~2.2.0"
}
}

My AppModule:

@NgModule({
declarations: [
AppComponent,
OpenDirective,
HeaderComponent,
NavigationSiteDirectoryComponent,
NavigationComponent,
FooterComponent,
ContentComponent,
HomeComponent,
LoadingComponent,
OpenEngineeringModelModalComponent,
LogoutComponent,
ModalContainerComponent,
ModelNavigationContainerComponent,
NavigationModelComponent,
ControlSideBarComponent
],
imports: [
BrowserModule,
HttpModule,
APP_ROUTER_PROVIDERS,
FormsModule,
ReactiveFormsModule,
CommonModule,
CDP4SharedModule,
RequirementModule,
SiteDirectoryModule,
EngineeringModelModule,
RIDModule,
EngineeringModelDataNoteModule,
FileStoreModule
],
providers: [
{provide: APP_BASE_HREF, useValue: '/'},
BusyIndicatorService,
ThingUpdateService,
WebServiceClient,
CdpServicesDal,
ModelNavigationService,
UserSessionService,
SiteDirectoryResolver,
EngineeringModelResolver,
DialogService,
ValidationService,
TreeTableService,
RequirementTreeTableService,
SharedTreeTableService,
FileStoreTreeTableService,
PersonTreeTableService,
ConfigService,
{provide: APP_INITIALIZER, useFactory: initConfig, deps: [ConfigService], multi: true }
],
bootstrap: [AppComponent]
})

export class AppModule {
}

Any ideas why it might happen and how to solve it?
Thanks.

@IevhenIkonnykov
Copy link

Just to add - when I delete a few components I finish with a problem described here.
In both cases I use Angular cli.

@PostImpatica
Copy link

Are you guys saying that any 3rd party library that has "@angular/core":"^2.0.0" (as an example) in it's package.json won't work when imported as a module? This is a nightmare, none of my 3rd party libraries work if this is the case.

@PostImpatica
Copy link

Never mind. My issue was related to the DLLReferencePlugin in Webpack. I had to clean my dll directory and rebuild them.

@afisher88
Copy link

You can also get this error if you declare a component in the imports array.

@Lavaei
Copy link

Lavaei commented May 6, 2017

Maybe you have "node_modules" directory in your sub directories!

@FriOne
Copy link

FriOne commented May 6, 2017

Hello! I have the same problem, I forked a library to make it work with angular cli aot, but no luck.
Could anyone look at my fork? It is very simple module.
An error is

ERROR in Unexpected value 'Ng2FlatpickrModule in .../node_modules/ng2-flatpickr/lib/ng2-flatpickr.module.js' imported by the module 'AppModule in .../src/app/app.module.t
s'. Please add a @NgModule annotation.

@prateekvarma
Copy link

prateekvarma commented May 9, 2017

I'm facing a similar issue. However, i get this error when i try to register a service on my Angular4 app. The error i see strangely is for another component (which works fine when the service is removed) :/
Edit : Ignore my comment, i had a typo

@dougludlow
Copy link

I ran into this using angular-cli and after quite a bit of digging found that it had to do with the generated polyfills.ts. In it, it imports the core-js versions of reflect:

import 'core-js/es6/reflect';
import 'core-js/es7/reflect';

I commented those out and imported reflect-metadata:

import 'reflect-metadata';

Things started working just fine after. Not exactly sure why this works... my understanding was that core-js simply included the reflect-metadata polyfill...

@AckerApple
Copy link

I was searching all over for tips on this error. Turns out I forgot to add "typings":"index.d.ts" to my package.json file

@irontoby
Copy link

I was having this error which turned out to be as @Lavaei suggested. I was doing local development on my shared module in a different project, and used yarn link to use the local copy. I had run yarn install in the linked copy, to make development easier (intellisense in VS Code, etc.)

As soon as I deleted node_modules from the local shared project, this error went away. I'm also using Angular CLI.

Is it possible to tell Angular CLI to ignore these node_modules in my local copy of the shared repo? It would be nice to be able to both serve this shared repo directly (I have a "shell app" that displays some of the common components) as well as use it from a different repo with yarn link.

@etwillbefine
Copy link

Can confirm @irontoby
I had the same issue and after removing node_modules and reinstall the error was gone.
Using angular-cli as well. It happen for me after upgrading from 4.1.0 to 4.2.0-rc.0

@josenriq
Copy link

I've tried everything mentioned in this issue to no avail. Using the latest Angular packages (5.0.1), no matter what I try, I keep getting the same error:

Unexpected value 'MyCustomModule' imported by the module 'AppModule'. Please add a @NgModule annotation.
  • There is no internal node_modules inside node_modules/my-custom-module
  • All @angular/* dependencies are specified as peerDependencies
  • Tried different configuration settings in the custom library's tsconfig.json. Tried skipTemplateCodegen both true and false (because of @robwormald comment above)

This was all working fine before.

@IevhenIkonnykov
Copy link

@linktothapast Unfortunately this is a very sneaky error that can be caused by different reasons. The last time I experienced this when I was adding a module to the root module and it had BrowserModule and BrowserAnimationsModule imported in it and this was my mistake. At least be sure that two above mentioned modules imported only once and only in the root module, otherwise you can have errors that are not very descriptive. Use CommonModule in your other modules instead of BrowserModule. In my case I had the same error as you and it was about the module that was totally fine. I hope it might be helpful. Also please check your imports, declarations, exports that everything on its place. I mean there is not a case that you declared a module in declarations or imported service etc. These kinds of mistake might cause weird errors as well.

@bentedder
Copy link

Similar to @linktothapast I have tried everything I can think of. I've created 2 simple angular 5 projects, one to package up, and one to consume. I use npm link to connect them, and I've put the files in a Plunkr for the packaged file to see if anybody knows what I'm doing wrong. Can't think of any other way but rolling back and waiting a few more weeks until smarter people than me run into the problem and post a fix :). The projects themselves build and run fine, it's only when exporting for library usage.

https://plnkr.co/edit/bOzJh5ncDSBKGoHggfDI?p=info

@ghost
Copy link

ghost commented Nov 17, 2017

@benelliott yep, I've been waiting for a solution for months now and this kind of stuff is a blocker to working with Angular. While I love promoting Angular for larger web dev teams because at its core it is a good framework, all these infrastructure issues and all the work that the Angular team has taken on is leading to lots of time wasted debugging issues like this.

@mmastrangelo
Copy link

I am having this problem as well. We will be stuck on version 1.2.7 of the CLI until a solution is available. Note that this issue is particularly challenging for anyone on NPM 5 as it links projects by default that are specified via "file:" in package.json. The only way to make it work is to remove node_modules from my linked modules... which is not viable within our dev workflow.

@d42ohpaz
Copy link

This is a closed ticket; not sure the devs look at replies to closed tickets. Maybe time to open a new ticket?

Also, I wanted to point out that, at least for me, I found and mirrored setting up my modules as demonstrated in the ngx-rocket/starter-kit and it has worked well ever since. The only gotcha is when my IDE decides to use the shortcut notation (e.g., @shared/whatever) inside of a module when it shouldn't.

@lazarljubenovic
Copy link
Contributor

Same issue here. Had a library written in 4.4.4. After updating to 5.0.x, the only change I made was tweak the build process to use the new function signature of ngc, and then this error started popping up. I've check out the metadata file that I'm generating and it looks pretty fine to me:

{
  "__symbolic": "module",
  "version": 4,
  "metadata": {
    "YahteeDatePickerModule": {
      "__symbolic": "class",
      "decorators": [
        {
          "__symbolic": "call",
          "expression": {
            "__symbolic": "reference",
            "module": "@angular/core",
            "name": "NgModule"
          },
          "arguments": [
            {
              "imports": [
                {
                  "__symbolic": "reference",
                  "module": "@angular/common",
                  "name": "CommonModule"
                }
              ],

I am consuming the library via npm repo (no links involved, like a few comments above pointed out). It was all working fine when the lib was built using 4.x and consumed via 5.x. Now when the lib is built wit 5.x and used via 5.x, it breaks runtime with the following error.

ERROR Error: Uncaught (in promise): Error: Unexpected value 'YahteeDatePickerModule' imported by the module 'DatePickerModule'. Please add a @NgModule annotation.
Error: Unexpected value 'YahteeDatePickerModule' imported by the module 'DatePickerModule'. Please add a @NgModule annotation.

The consuming project is using CLI 1.5.

@rudzikdawid
Copy link

i have similar problem with @angular/cli 1.4.9 here https://github.com/swiety85/angular2gridster/tree/137-demo-src-app-gridster

dir structure:

angular2gridster
├─ demo //angular-cli app
│  └─ src
└─ src //library source

reproduce steps:

cd angular2gridster
npm link
cd demo
npm link angular2gridster 

falubas
after that in demo/node_modules we have linked angular2gridster package but with library's node_modules which unfortunately contain @angular/core

start demo ng serve --preserve-symlinks affects error:

Uncaught Error: Unexpected value 'GridsterModule'
imported by the module 'AppModule'. Please add a @NgModule annotation.

messy workaround

removing demo/node_modules/angular2gridster/node_modules/@angular/core
solves the problem temporary but after that we can't rebuild library.

path mapping inside demo/src/tsconfig.app.json also doesn't help:

"baseUrl": ".",
"paths": {
   "@angular/core": ["../node_modules/@angular/core"]
 }

library dependecies:

"peerDependencies": {
    "@angular/common": "4.4.6",
    "@angular/core": "4.4.6"
  },
  "devDependencies": {
    "@angular/common": "4.4.6",
    "@angular/compiler": "4.4.6",
    "@angular/compiler-cli": "4.4.6",
    "@angular/core": "4.4.6",
    "@angular/language-service": "4.4.6",
    "@types/node": "~6.0.60",
    "codelyzer": "^3.0.1",
    "reflect-metadata": "~0.1.9",
    "rxjs": "^5.5.2",
    "ts-loader": "^2.0.1",
    "ts-node": "~3.0.4",
    "tslint": "~5.3.2",
    "typescript": "2.4.2",
    "zone.js": "^0.8.4"
  }

demo dependencies:

"dependencies": {
    "@angular/animations": "4.4.6",
    "@angular/common": "4.4.6",
    "@angular/compiler": "4.4.6",
    "@angular/core": "4.4.6",
    "@angular/forms": "4.4.6",
    "@angular/http": "4.4.6",
    "@angular/platform-browser": "4.4.6",
    "@angular/platform-browser-dynamic": "4.4.6",
    "@angular/router": "4.4.6",
    "core-js": "^2.5.1",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "1.4.9",
    "@angular/compiler-cli": "4.4.6",
    "@angular/language-service": "4.4.6",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.0.1",
    "gh-pages": "^1.1.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.0.4",
    "tslint": "~5.3.2",
    "typescript": "2.4.2"
  }

any idea?

@OnlyBelter
Copy link

I also met this problem: same code works on Windows, but not works on Linux.

This is my version infomation:

windows

Angular CLI: 1.5.0
Node: 8.1.4
OS: win32 x64
Angular: 4.3.6
... common, compiler, compiler-cli, core, forms, http
... language-service, platform-browser, platform-browser-dynamic
... router, tsc-wrapped

@angular/animations: 4.4.6
@angular/cli: 1.5.0
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@schematics/angular: 0.1.1
typescript: 2.3.4
webpack: 3.8.1

linux

Angular CLI: 1.5.0
Node: 6.11.3
OS: linux x64
Angular: 4.4.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, tsc-wrapped

@angular/cli: 1.5.0
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.1
typescript: 2.3.4
webpack: 3.8.1

Then I updated the nodejs on linux from 6.11.3 to 8.9.3, deleted all dependencies then used npm install to re-install all dependencies. It works now.

@bDino
Copy link

bDino commented Dec 12, 2017

Had the same problem - turned out the ng-pdf-make project had a subdirectory of node_modules with its own angular version which caused the bug. After deleting the local node_modules it worked!

@srinivas444
Copy link

I also faced the same issue but resolved by updating the tsconfig.app.json with following code:

{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"baseUrl": "",
"types": [],
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
],
"paths": {
"@angular/": [
"../node_modules/@angular/
"
]
}
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}

Its worked for me try it from your end.

@raviprajna
Copy link

I am also facing same issue

Uncaught Error: Unexpected value 'Http' imported by the module 'AppModule'. Please add a @NgModule annotation.
at syntaxError (compiler.js:215)
at compiler.js:10468
at Array.forEach ()
at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNgModuleMetadata (compiler.js:10443)
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._loadModules (compiler.js:22567)
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:22548)
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler.compileModuleAsync (compiler.js:22508)
at CompilerImpl.push../node_modules/@angular/platform-browser-dynamic/fesm5/platform-browser-dynamic.js.CompilerImpl.compileModuleAsync (platform-browser-dynamic.js:143)
at PlatformRef.push../node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModule (core.js:4790)
at Object../src/main.ts (main.ts:11)

@Jayawardhana
Copy link

i used flash-message new version then i have this error in browser

[WDS] Disconnected!
vendor.bundle.js:67956:10
Error: Unexpected module 'FlashMessageModule' declared by the module 'AppModule'
zone.js:992

This is app.module.ts

// Required Fields
if(!this.validateService.validateRegister(user)){
this.flashMessage.warning('Please fill in all fields', {cssClass:'alert-danger', timeout:3000});
return false;
}

// Validate Email
if(!this.validateService.validateEmail(user.email)){
  this.flashMessage.warning('Please use a valid email', {cssClass:'alert-danger', timeout:3000});
  return false;
}

@lazarljubenovic
Copy link
Contributor

@Jayawardhana This is not a support group. Please post your question on Stack Overflow. And it does make sense, you do not declare a module in a module, you import it.

@rsprince
Copy link

Unhelpful and negative.

@lazarljubenovic
Copy link
Contributor

It's not negative, it's a fact. Hijacking an issue with a "fix this code please" only creates noise for everyone. I've not only pointed the user in the right direction (StackOverflow), I've actually given a strong hint towards the solution:

you do not declare a module in a module, you import it

So there's nothing negative about it and there's for sure a few things helpful there.

@vilbara
Copy link

vilbara commented Dec 17, 2018

Got the same error with angular v7 with an in-project library created with angular-cli. The cause in my case was that the components and modules were exported in public_api.ts via intermediate index.ts files. Removing index.ts files and exporting everything directly in public_api.ts solved this.

Pretty sure there is a good technical explanation for this, but from the perspective of a simple "user" this belongs to the category of "insane"!

@nejsimon
Copy link

Got the same error with angular v7 with an in-project library created with angular-cli. The cause in my case was that the components and modules were exported in public_api.ts via intermediate index.ts files. Removing index.ts files and exporting everything directly in public_api.ts solved this.

Thanks! This solved the problem for me as well. The error message you get is remarkably unhelpful.

@yanqiw
Copy link

yanqiw commented Jul 15, 2019

Got the same error with angular v7 with an in-project library created with angular-cli. The cause in my case was that the components and modules were exported in public_api.ts via intermediate index.ts files. Removing index.ts files and exporting everything directly in public_api.ts solved this.

Pretty sure there is a good technical explanation for this, but from the perspective of a simple "user" this belongs to the category of "insane"!

this one save me.

@kimamula
Copy link

Got the same error with angular v7 with an in-project library created with angular-cli. The cause in my case was that the components and modules were exported in public_api.ts via intermediate index.ts files. Removing index.ts files and exporting everything directly in public_api.ts solved this.

Thanks!
Specifying index.ts explicitly in public_api.ts (i.e., export * from './some-module/index') also works.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests