模块构建失败:错误:调试失败。错误的表达

时间:2018-10-04 09:48:36

标签: angular typescript compilation

我在打字稿中有一个库,可以将javascript类编译为:

ClassName = ClassName_1 = class ClassName{
...
}

ClassName = ClassName_1 = decorate([
...])

当我使用依赖于此库的有角度的前端进行编译时,这会产生错误:

./node_modules/.bin/ng build --configuration=development --base-href /client/ --deploy-url /client/

给出以下错误:

ERROR in ./node_modules/library/ClassName.js
Module build failed: Error: Debug Failure. False expression.

我使用打字稿2.9.2编译所有内容,因为它是Angular 6项目。我尝试将7.0.0-rc与`3.0.3一起使用,但仍然出现此错误,但是在这里我可能会有一个假阴性。

如果我手动更改.js文件,它将起作用:

ClassName = class ClassName{
...
}
ClassName_1 = ClassName

ClassName = ClassName_1 = decorate([
...])
ClassName_1 = ClassName

出现此错误的代码是:

/**
 * Endpoint gives the baseDomain of MultiChat and gives the appropriate protocol.
 * This is useful so you can pass through the same object to resources and streams types.
 *
 * A custom object is introduced to allow to pass the same object to use for WebSockets and https calls.
 * Paths are also added to easily construct full routes.
 *
 * The design is to return full new objects so that you do not mix references.
 */
@injectable()
export class Endpoint {

    public secure: boolean;
    public baseDomain: string;
    public paths: string[];
    public port: number;
    public queries: Map<string, string>;

    /**
     * init initializes the Endpoint with the correct baseDomain.
     * @param secure is true if the _endpoint is reachable by HTTPS and WSS
     * @param baseDomain the basedomain of the _endpoint, eg. independer.nl.
     * @param paths additional paths to the _endpoint without slashes, eg. ["api"]
     * @param port the port the _endpoint is hosted on
     */
    constructor(secure: boolean, baseDomain: string, paths: string[] = [], port?: number) {
        this.baseDomain = baseDomain;
        this.paths = paths;
        this.port = port;
        this.secure = secure;
        this.queries = new Map<string, string>();
    }

    /**
     * addPath returns a new Endpoint object with the paths added and returns a clone of the Endpoint.
     * @param paths
     */
    public addPath(paths: string[]): Endpoint {
        const result = this.cloneEndpoint();

        result.paths = this.paths.concat(paths);

        return result;

    }

    /**
     * addQuery adds a new query parameter and returns a clone of the Endpoint.
     * @param key The key of the parameter.
     * @param value The value of the parameter.
     */
    public addQuery(key: string, value: string): Endpoint {
        const result = this.cloneEndpoint();

        result.queries.set(key, value);

        return result;
    }

    /**
     * getHTTP returns the HTTP baseDomain string.
     * If the baseDomain is secure it returns HTTPS.
     */
    public getHTTP(): string {
        const protocol = (this.secure ? "https" : "http");

        return this.getEndpoint(protocol);
    }

    /**
     * getWS returns the WebSocket baseDomain string.
     * * If the baseDomain is secure it returns WSS.
     */
    public getWS(): string {
        const protocol = (this.secure ? "wss" : "ws");

        return this.getEndpoint(protocol);
    }

    private cloneEndpoint(): Endpoint {
        return new Endpoint(this.secure, this.baseDomain, this.paths, this.port);
    }

    private getEndpoint(protocol: string) {
        const port = (this.port ? ":" + this.port : "");

        let endpoint = protocol + "://" + this.baseDomain + port;

        endpoint += this.getPath();

        if (this.queries.size) {
            endpoint += "?";

            let first = true;
            for (const key of this.queries.keys()) {
                if (!first) {
                    endpoint += "&";
                }

                endpoint += key + "=" + encodeURIComponent(this.queries.get(key));

                first = false;
            }
        }

        return  endpoint;
    }

    private getPath(): string {
        let fullPath = "";

        for (const path of this.paths) {
            fullPath += "/" + path;
        }

        return fullPath;
    }

}

1 个答案:

答案 0 :(得分:0)

我复制了TypeScript 2.9.2的错误。堆栈跟踪:

Error: Debug Failure. False expression.
    at Object.getJSDocTags (.../typescript/lib/tsc.js:10302:22)
    at getJSDocTypeParameterDeclarations (.../typescript/lib/tsc.js:9069:30)
    at Object.getEffectiveTypeParameterDeclarations (.../typescript/lib/tsc.js:9065:67)
    at checkClassLikeDeclaration (.../typescript/lib/tsc.js:40190:36)
    at checkClassExpression (.../typescript/lib/tsc.js:40166:13)
    at checkExpressionWorker (.../typescript/lib/tsc.js:37693:28)
    at checkExpression (.../typescript/lib/tsc.js:37629:42)
    at checkBinaryLikeExpression (.../typescript/lib/tsc.js:37246:29)
    at checkBinaryExpression (.../typescript/lib/tsc.js:37238:20)
    at checkExpressionWorker (.../typescript/lib/tsc.js:37717:28)

我没有看到现有的问题,但是TypeScript 3.0.3或3.1.3都没有错误。我建议您再次尝试3.0.3,然后尝试确认该版本已被实际使用。 (一种简单的方法是将unknown粘贴在代码中的某个位置,看看是否可以识别它。)

解决方案的另一种途径是阻止TypeScript加载有问题的JavaScript文件。我不熟悉Angular构建系统来了解所有选项,但是可能要做的一件事是打开库的声明文件(.d.ts)生成,并确保生成的{{ 1}}文件在生成应用程序时与.d.ts文件并存,因此TypeScript将加载.js文件而不是.d.ts文件。这也可能会为您提供高级的类型信息。