【问题标题】:Build: '(' expected in *.d.ts files. Cannot compile TypeScript project构建:*.d.ts 文件中需要“(”。无法编译 TypeScript 项目
【发布时间】:2016-12-13 07:40:34
【问题描述】:

我正在尝试在 Visual Studio 2015 中构建我的 Angular 2 TypeScript asp.net 核心项目,但我看到的是:

严重性代码描述项目文件行抑制状态 错误 TS1005 构建:'(' 预期的。 MExplore C:\Users\Piotrek\documents\visual studio 2015\Projects\MProjects\MExplore\wwwroot\lib\@angular\core\esm\src\linker\query_list.d.ts 36
错误 TS1005 构建:'(' 预期的。 MExplore C:\Users\Piotrek\documents\visual studio 2015\Projects\MProjects\MExplore\wwwroot\lib\@angular\compiler\esm\src\output\output_interpreter.d.ts 7
错误 TS1005 构建:'(' 预期的。 MExplore C:\Users\Piotrek\documents\visual studio 2015\Projects\MProjects\MExplore\wwwroot\lib\@angular\compiler\esm\src\output\output_interpreter.d.ts 8
错误 TS1005 构建:'(' 预期的。 MExplore C:\Users\Piotrek\documents\visual studio 2015\Projects\MProjects\MExplore\wwwroot\lib\@angular\compiler\esm\src\output\output_interpreter.d.ts 9
错误 TS1005 构建:'(' 预期的。 MExplore C:\Users\Piotrek\documents\visual studio 2015\Projects\MProjects\MExplore\wwwroot\lib\@angular\common\esm\src\forms-deprecated\model.d.ts 53
错误 TS1005 构建:'(' 预期的。 MExplore C:\Users\Piotrek\documents\visual studio 2015\Projects\MProjects\MExplore\wwwroot\lib\@angular\common\esm\src\forms-deprecated\model.d.ts 98
错误 TS1005 构建:'(' 预期的。 MExplore C:\Users\Piotrek\documents\visual studio 2015\Projects\MProjects\MExplore\wwwroot\lib\@angular\common\esm\src\forms-deprecated\model.d.ts 52

等等……

因此,这些 3743 错误的基本模式是:

构建:'[something]' 预期。

出现问题的文件总是以*.d.ts结尾。

我认为这是打字的问题,但我的引导程序中有适当的参考(main.ts 文件)

///<reference path="./../../typings/globals/core-js/index.d.ts"/>

以及里面的那些参考:

/// <reference path="globals/core-js/index.d.ts" />
/// <reference path="globals/jasmine/index.d.ts" />
/// <reference path="globals/node/index.d.ts" />

我以前用过很多次,效果很好……

我还使用 gulp ('gulp-typescript') 将 typescript 编译为 javascript 并将其复制到其他地方。它运行良好,没有显示错误。所以也许我的代码本身没有问题,而是我在 Visual Studio 中配置错误?

你怎么看?

【问题讨论】:

    标签: typescript angular


    【解决方案1】:

    According to this GitHub issue, *.d.ts 文件应从编译中排除。所以,基本上,这就是你应该在tsconfig.json 文件中做的事情:

    {
      [...]
      [some stuff]
      [...]
      "exclude": [
        "folder_where_you_have_those_faulty_files"
      ]
    }
    

    Comment 1:

    您应该从 tsc 构建中排除一些文件夹,以*避免*编译 .d.ts 文件。

    Comment 2:

    无论您使用哪个 typescript 版本,关键都不是编译 *.d.ts。在您的项目中,您应该排除所有 *.d.ts 编译以摆脱此问题。

    谢谢你,@danny8002!

    【讨论】:

    • 但是tsconfig和CSProj是互斥的,我们如何排除csproj中的那些文件!
    • 我已经在排除数组中有 node_modules 文件夹。但无论如何它包括它。
    【解决方案2】:

    只有在构建 Visual Studio 时,我才收到此错误 TS110 Build Typescript expected core.d.ts。当 Visual Studio 构建时,它使用 tsc -w。这会导致它构建目录下的所有文件 *.ts 并且它不区分 *.d.ts 和 *.ts,因此将尝试编译它们。 *.d.ts 文件是类型定义文件,无法编译。所以你只需要告诉 ts 忽略 node_modules 文件夹。

    您可以通过将以下 "exclude" : [ "node_modules","typings"] 添加到 tsconfig.json 来做到这一点。您应该始终忽略这两个文件夹。

    {
        "compilerOptions": {
            "module": "system",
            "noImplicitAny": true,
            "removeComments": true,
            "preserveConstEnums": true,
            "outFile": "../../built/local/tsc.js",
            "sourceMap": true
        },
        "include": [
            "src/**/*"
        ],
        "exclude": [
            "node_modules","typings"
          ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-06
      • 2019-04-24
      • 2017-04-02
      • 2018-11-23
      • 2018-04-05
      • 2020-05-02
      • 2019-09-24
      相关资源
      最近更新 更多