加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular2,预编译功能模块时的元数据错误

发布时间:2020-12-17 07:15:01 所属栏目:安全 来源:网络整理
导读:我正在使用Angular2 RC6编写Angular2库. 该库包含一个模块: import { Component,OnInit,NgModule } from '@angular/core';import { CommonModule } from '@angular/common';@Component({ selector: 'yeva',template: 'div/div'})export class YevaComponent
我正在使用Angular2 RC6编写Angular2库.

该库包含一个模块:

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 {

}

如果我将此代码复制粘贴到现有Angular2应用程序中的TypeScript文件中,并尝试直接使用此模块,则它可以完美地运行…

但我的目标是建立一个外部的npm库.

如果我在一个独立项目中移动这个完全相同的代码:

https://github.com/ClementVidal/starter.yeva

(此项目配置为用作Angular2库,使用TypeScript进行编译,以供客户端应用程序使用.)

我收到以下错误:

模块’AppModule’导入的意外值’YevaModule’

以下是我在两种情况下导入模块的方法:

@NgModule({
  imports: [BrowserModule,YevaModule],declarations: [AppComponent],providers: [
    FOUNDATION_PROVIDERS
  ],bootstrap: [AppComponent]
})
export class AppModule {

}

此错误来自Angular编译器:

var importedMeta = _this.getNgModuleMetadata(importedModuleType,false);
if (importedMeta === null) {
   throw new Error("Unexpected " + _this._getTypeDescriptor(importedType) + " '" + stringify(importedType) + "' imported by the module '" + stringify(moduleType) + "'");
}

看来我的模块作为预编译模块导入时不包含任何元数据.

我试着通过查看编译后的代码来解决这个问题,但我没有找到任何东西……

以下是重现此错误的方法:

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

然后浏览到http://localhost:8080/

你们中有没有人已经尝试过这类问题吗?

解决方法

似乎应该由库作者提供一个或多个元数据文件,每个.d.ts定义文件一个.元数据文件由Angular AOT编译器(angular-cli)生成.

以下是对角色的引用:

> #11262,a comment
> #11262,another comment

下面是一个库作者应用更改以支持AOT编译器的示例:

> feature(build): Added @angular/compiler-cli support

我也在为另一个库添加支持并将其作为PR提交

HTH

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读