【问题标题】:angular 2 - PrimeNg teamcity/visual Studio compilation failing (exclude node_modules)角度 2 - PrimeNg teamcity/visual Studio 编译失败(不包括 node_modules)
【发布时间】:2017-05-14 15:48:03
【问题描述】:

您好,我正在使用 PrimeNg 数据表,它似乎无法在 teamcity 上构建。以下是错误

(CompileTypeScriptWithTSConfig 目标)-> node_modules\primeng\components\datatable\datatable.d.ts(180,14): 错误 TS1005:构建:预期为“=”。 node_modules\primeng\components\datatable\datatable.d.ts(180,25): 错误 TS1005:构建:';'预计。

知道 Visual Studio 编译失败的原因。打字似乎有问题,我需要在这个文件中手动修复这个问题吗?

这些行之前的一些行是

PreComputeCompileTypeScriptWithTSConfig:

[13:34:52][步骤 1/1] C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe --project "E:\buildagent\work\2be75659b1819119\src\MyProject.Client\e2e\tsconfig.json"

[13:34:52][步骤 1/1] C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe --project "E:\buildagent\work\2be75659b1819119\src\MyProject.Client\src\tsconfig.json"

[13:34:52][步骤 1/1] CompileTypeScriptWithTSConfig:[13:34:52][步骤 1/1] C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe --project "E:\buildagent\work\2be75659b1819119\src\MyProject.Client\e2e\tsconfig.json"

[13:34:54][步骤 1/1] C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe --project "E:\buildagent\work\2be75659b1819119\src\MyProject.Client\src\tsconfig.json"

我的 tsconfig 在下面

{
  "compileOnSave": false,
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "mapRoot": "/",
    "module": "commonjs",
    "moduleResolution": "node",
    "noEmitOnError": true,
    "noImplicitAny": false,
    "outDir": "../dist/",
    "rootDir": ".",
    "sourceMap": true,
    "target": "es5",
    "inlineSources": true
  },

  "files": [
    "main.ts",
    "typings.d.ts"
  ],
  "exclude": [
    "../node_modules/*",
    "typings",
    "**/*-aot.ts"
  ]

}

为什么不忽略 node_modules 编译

【问题讨论】:

  • 首先,您使用的是哪个版本的 PrimeNg?其次,向我们展示您的 tsconfig 和编译任务,以确定您正在转译哪些 TypeScript 文件。
  • 我正在使用“primeng”:“^1.0.0”
  • 我认为问题是 tsc 正在尝试编译 node_modules 文件,我似乎无法忽略此文件夹。

标签: visual-studio angular compiler-errors typescript-typings primeng


【解决方案1】:

如果您想忽略 VS 的 TypeScript 自动编译,请将 tsconfig.json 重命名为 tsconfig.jsonx 之类的名称。然后在您的 gulp 脚本(或首选构建环境)中使用重命名的文件。

当您的 VS csproj 中有 tsconfig.json 时,请检查属性。你会发现 VS 会在“TypeScript Build”部分自动检测到它。

在我的 gulp 脚本中,我将新的 ts 配置文件用作:

var tsProject = ts.createProject('tsconfig.jsonx');

// compile ts files and put it in dist
gulp.task('compile', ['clean'], function () {
    return tsProject.src()
        .pipe(tsProject())
        .js.pipe(gulp.dest("dist/app"));
});

有点 hack,但如果你需要的话,这是避免 MS Build 的一种方法

【讨论】:

    【解决方案2】:

    我已经修复了,看来 Tyescript 1.8 有 bug,不包括 node_modules。

    我将 Typescript 升级到 2.1,并从 1.8 更改为 2.1

    <TypeScriptToolsVersion>1.8</TypeScriptToolsVersion>
    

    它似乎解决了问题并忽略了 node_modules 打字稿文件。我不确定如何告诉 VS 不要编译 Typescript 文件,这将是另一种解决方案。

    【讨论】:

    • 您在哪个文件中进行了此更改?
    猜你喜欢
    • 2018-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多