angular - 装饰器不支持对非导出类的引用
问题描述
我最近将 angular 项目从自定义 webpack 配置升级到了 angular-cli。当我运行时,一切都按预期工作,ng serve
但ng build --prod
出现以下错误。
谁能帮我解决这个问题?
looger.ts
class Message {
static show(name: string) {
return (ref?: any, ...parameters: any[]): void => {
//aadditional code
};
}
}
class Options {
static level: string[] = ['error', 'warn', 'info', 'debug', 'log', 'dir'];
static moduleNames: string[] = [];
static set(level: string[], moduleNames?: string[]) {
//aadditional code
}
}
export const Log = {
error: Message.show('error'),
warn: Message.show('warn'),
info: Message.show('info'),
debug: Message.show('debug'),
log: Message.show('log'),
dir: Message.show('dir'),
options: {
set: Options.set
}
};
app.module.ts
import { Log as log } from 'logger';
@NgModule({
providers: [
{ provide: log, useValue: log }
]
})
export class AppModule {
constructor() {}
}
解决方案
错误是导出. 所以大家在Message 类前面使用 export 关键字。
希望这将消除您在 prod 或 aot 构建期间的错误。
推荐阅读
- python - 将特定字符串转换为 pandas 数据框
- plsql - 使用 myBatis 查询 sysdate 有问题吗?
- r - 在 R 中透视/重塑数据
- javascript - jest.fn() 的别名?
- tensorflow - L-BFGS 是否有 tf.keras.optimizers 实现?
- android - 正则表达式删除除句点以外的所有特殊字符
- javascript - React Js onClick 下拉菜单打开
- amazon-web-services - AWS S3 - 指定的密钥不存在。- 对于上传的文件夹
- wpf - 在 OxyPlot 中设置 X 轴的 Y 位置
- r - 创建一个表,其中包含列数、行数、行中的 NA 数、列表中的数据帧数