Currently, I am in the process of developing an Angular2 library using Angular2 RC6.
This particular library consists of a single 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 {
}
When I directly integrate this code into an existing Angular2 application, it works seamlessly...
However, my objective is to create an external npm library.
Upon moving this identical code to a separate project:
https://github.com/ClementVidal/starter.yeva
(This project is structured to function as an Angular2 library, where TypeScript compilation is utilized to enable consumption in my client application.)
An error emerges:
Unexpected value 'YevaModule' imported by the module 'AppModule'
Here is how I import my module in BOTH contexts:
@NgModule({
imports: [BrowserModule,YevaModule],
declarations: [AppComponent],
providers: [
FOUNDATION_PROVIDERS
],
bootstrap: [AppComponent]
})
export class AppModule {
}
The error is coming 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 appears that my module, when imported as a precompiled module, lacks Metadata.
I have attempted to investigate this by examining the compiled code, but I have not discovered anything...
Here's a method to replicate this error:
mkdir test-metadata
cd test-metadata
git clone <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="13747a6753747a677b66713d707c">[email protected]</a>:ClementVidal/starter.yeva.git
git clone <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="eb8c829fab8c829f839e89c5888486">[email protected]</a>: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 navigate to http://localhost:8080/
Have any of you encountered a similar issue before?