首页 > 解决方案 > 装饰器不支持对非导出类的引用

问题描述

我最近将 angular 项目从自定义 webpack 配置升级到了 angular-cli。当我运行时,一切都按预期工作,ng serveng 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() {}
}

标签: angulartypescriptangular-cli

解决方案


错误是导出. 所以大家在Message 类前面使用 export 关键字。

希望这将消除您在 prod 或 aot 构建期间的错误。


推荐阅读