装饰器不支持对未导出类的引用

3

最近我将angular项目从自定义webpack配置升级到angular-cli。当我运行ng serve时,一切都按预期工作,但是运行ng build --prod时出现以下错误。

enter image description here

有人能帮我解决这个问题吗?

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() {}
}


你能理解错误信息的一部分吗? - Jota.Toledo
抱歉,@Jota.Toledo 我不能做到。 - Krishna
如果导出 MessageOptions 类,错误是否会消失? - ConnorsFan
刚刚我改了一下,出现了一个不同的错误。https://imgur.com/a/KZPWlNW - Krishna
1个回答

1
错误出现在导出上。 因此,各位需要在class Message前面使用export关键字。 希望这能够消除您在生产或aot构建期间的错误。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接