【问题标题】:Visual Studio 2017: TypeScript compile errors in node_modulesVisual Studio 2017:node_modules 中的 TypeScript 编译错误
【发布时间】:2017-12-23 09:07:20
【问题描述】:

尝试构建一个 Angular 应用程序时,我在 node_modules 文件夹中遇到 typescript 文件的编译错误。

例如:

TS2420:“CdkTable”类错误地实现了接口 'CollectionViewer'。

CdkTable 位于 @angular/cdk/typings/table/table.d.ts

我的工具版本:

npm -v: 5.0.3

节点-v:v8.1.4

tsc -v:版本 2.2.3

我的 tsconfig.json:

{
  "compilerOptions": {
    "moduleResolution": "node",
    "target": "es5",
    "sourceMap": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "skipDefaultLibCheck": true,
    "lib": [ "es6", "dom" ],
    "types": [ "node" ]
  },
  "exclude": [ "bin", "node_modules" ],
  "atom": { "rewriteTsconfig": false }
}

请注意,该项目可以在其他计算机上编译。

【问题讨论】:

    标签: visual-studio angular typescript


    【解决方案1】:

    我假设您的 tsc 可执行文件是通过 npm 安装的,并且是全局安装的。

    检查您已安装的适用于 Visual Studio 的 TypeScript SDK 的版本。它应该位于大致为:C:\Program Files (x86)\Microsoft SDKs\TypeScript 的文件夹中。确保此版本是最新版本(或至少与您全局安装的 TypeScript 版本相同)。

    还要检查您的环境变量,看看您的路径中是否有不同的版本。 Visual Studio 的 MSBuild 进程使用 MSBuild TypeScript tasks,它将从 SDK 安装中获取 TypeScript。这解释了命令行输出(使用全局安装的 tsc)和 Visual Studio 输出的差异。

    此外,还有 known issues 在 Visual Studio 项目中使用 tsconfig。我知道它应该得到完全支持,但是仍然有很多人报告我研究过的问题。当您右键单击项目并选择属性时,您可能希望删除 tsconfig 以支持使用可用的 TypeScript 选项卡。

    或者,您可以尝试设置 rootDir 编译器选项,以尝试找出您实际需要编译的 TypeScript 文件的目录。我知道excludes 应该阻止这种情况,但同样,Visual Studio 可能会以某种方式在 tsconfig 上打嗝。

    【讨论】:

    • 在“C:\Program Files (x86)\Microsoft SDKs\TypeScript”中我有几个版本,我删除了最新的 - 它是 2.4 现在它正在工作
    • 是的,2.4 更严格。这引起了很多人的问题。
    猜你喜欢
    • 2017-08-28
    • 2018-12-08
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 1970-01-01
    • 2019-04-01
    相关资源
    最近更新 更多