gpt4 book ai didi

angular - 在 Angular 2 服务中导入自定义声明文件时出现 "Error: Debug Failure. False expression: Output generation failed"

转载 作者:行者123 更新时间:2023-12-03 16:28:19 30 4
gpt4 key购买 nike

我有一个旧的、令人讨厌的 JavaScript 文件,里面装满了我需要提供给我的 Angular 服务的东西,但我不知道该怎么做。我很惊讶找到一个教程是多么困难。也许我只是太脱离循环以至于我什至不知道如何问这个问题......
我已经为它创建了一个声明文件(假设它被称为 oldstuff.d.ts )。
澄清:这只是一个声明文件。实际代码位于不同的文件中:oldstuff.js在我的 Angular 服务的顶部,我正在导入声明文件,如下所示:

import './oldstuff.d';
我没有在应用程序的任何地方做任何其他事情来尝试包含声明文件。
此导入足以让 VS Code 识别定义,并且所有智能感知都按我的预期工作。
事实上,我什至可以使用 Angular CLI 来构建项目,而且看起来构建还可以。
然而 ,一旦我尝试将此服务注入(inject)应用程序中其他位置的构造函数,构建就会失败并出现以下错误:
ERROR in ./src/app/oldstuff.d.ts
Module build failed: Error: Debug Failure. False expression: Output generation failed
at Object.assert (c:\Projects\Angular\MyApp\node_modules\typescript\lib\typescript.js:3329:23)
at Object.transpileModule (c:\Projects\Angular\MyApp\node_modules\typescript\lib\typescript.js:80449:18)
at TypeScriptFileRefactor.transpile (c:\Projects\Angular\MyApp\node_modules\@ngtools\webpack\src\refactor.js:166:27)
at Promise.resolve.then.then.then.then (c:\Projects\Angular\MyApp\node_modules\@ngtools\webpack\src\loader.js:414:37)
@ ./src/app/my-app.module.ts 23:0-34
@ ./src/main.ts
@ multi ./src/main.ts
我已经在谷歌上搜索了那个特定的错误消息,以及关于如何包含声明文件的一般信息,我快干了。
以下是我看过的一些内容:
  • https://angular.io/guide/typescript-configuration
  • https://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html
  • https://www.bennadel.com/blog/3169-adding-custom-typings-files-d-ts-in-an-angular-2-typescript-application.htm
  • https://github.com/angular/angular/issues/11567
  • https://github.com/angular/angular-cli/issues/6736
  • https://github.com/s-panferov/awesome-typescript-loader/issues/225

  • 我遇到了一个合法的错误,还是我做错了?

    最佳答案

    好吧,这看起来很愚蠢,但我所要做的就是从文件名中删除字母“d”。
    所以,而不是这个:

    //actual filename: oldstuff.d.ts
    import './oldstuff.d';
    我有这个:
    //actual filename: oldstuff.ts
    import './oldstuff'
    现在它按预期在运行时构建和工作。我对 Typescript 的理解不够好,无法理解这是否是预期的行为。

    关于angular - 在 Angular 2 服务中导入自定义声明文件时出现 "Error: Debug Failure. False expression: Output generation failed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46207258/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com