I am writing an Angular2 library using Angular2 RC6.
This library contains one module:
import { Component, OnInit, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; @Component({ selector: 'yeva', template: '<div></div>' }) export class YevaComponent { constructor() { } } @NgModule({ imports: [CommonModule], declarations: [YevaComponent], providers: [], exports: [YevaComponent] }) export class YevaModule { }
If I copy this code to a TypeScript file in an existing Angular2 application and try to use this module directly, it works fine ...
But my goal here is to build an external npm library.
If I translate this exact code in a standalone project:
https://github.com/ClementVidal/starter.yeva
(This project is configured to be used as an Angular2 library, where it compiles using TypeScript to be used by my client application.)
I get the following error:
Unexpected value "YevaModule" imported by the module "AppModule"
This is how I import my module in BOTH cases:
@NgModule({ imports: [BrowserModule,YevaModule], declarations: [AppComponent], providers: [ FOUNDATION_PROVIDERS ], bootstrap: [AppComponent] }) export class AppModule { }
This error comes from the Angular compiler:
var importedMeta = _this.getNgModuleMetadata(importedModuleType, false); if (importedMeta === null) { throw new Error("Unexpected " + _this._getTypeDescriptor(importedType) + " '" + stringify(importedType) + "' imported by the module '" + stringify(moduleType) + "'"); }
It seems that my module when importing as a precompiled module does not contain metadata .
I tried to figure this out by looking at the compiled code, but found nothing ...
Here's how to reproduce this error:
mkdir test-metadata cd test-metadata git clone git@github.com :ClementVidal/starter.yeva.git git clone git@github.com :ClementVidal/starter.themba.git cd starter.yeva npm install sudo npm link cd ../starter.themba git checkout module-metadata sudo npm link __TITLE__ npm install npm run server
Then go to http: // localhost: 8080 /
Are any of you already experimenting with this type of problem?