【问题标题】:Typescript compile on save is not working when tsconfig.json is in project当 tsconfig.json 在项目中时,Typescript compile on save 不起作用
【发布时间】:2016-09-26 11:53:11
【问题描述】:

当我保存时,我无法让 Visual Studio 运行 typescript 编译到 js。

我有一个 xproj(带有网络框架的 asp.net 核心) 用于 Visual Studio 2015 更新 3 的 TypeScript 2.0.3 工具。

我尝试在 tsconfig.json 中启用"watch" : true,但它说当前主机不受支持。

我去了工具 > 选项 > 文本编辑器 > TypeScript > 项目并启用“自动编译不属于项目的 TypeScript 文件”

不过,.ts 文件中的更改只会在编译期间反映在 .js 文件中,但只有在必须编译的 c# 服务器端文件发生更改时才会反映。

编辑:我发现即使配置文件为空,项目目录中简单存在的 tsconfig.json 也会阻止编译保存。

目前可以以某种方式修复吗?

这是我的 tsconfig.json 的内容:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "diagnostics": true
  },
  "include": [
    "**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

EDIT 2:我也试过了:

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "diagnostics": true
  },
  "filesGlob": [
    "**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

它什么也没做。

【问题讨论】:

  • 我也有同样的问题。此外,自安装 Update 3 和 Typescript 2.0.3 以来,智能感知不再工作。有人有解决办法吗?

标签: visual-studio typescript


【解决方案1】:

我卸载了 Visual Studio 2015 和 Typescript 2.0.3。然后我重新安装了 Visual Studio 2015。打开我的解决方案并检查 Typescript 1.8.3 后,我安装了 Typescript 2.0.3 并在“compilerOptions”之前添加了“compileOnSave”。从那时起它对我有用。添加此选项后,您需要重新启动 Visual Studio。

{
  "compileOnSave": true,
  "compilerOptions": {
  ...
}

【讨论】:

  • 您需要重新启动 Visual Studio!那是一个小混蛋!谢谢@Bluesight
【解决方案2】:

"compileOnSave":true 添加到 tsconfig.json 应该可以解决问题:

{
  "compileOnSave": true,
  "compilerOptions": {
  ...

【讨论】:

  • 我也这么认为,但这是默认选项,并没有奏效。
【解决方案3】:

将 tsconfig.json compileOnSave 设置为 true

{
   "compileOnSave": true,

   "compilerOptions": {
     "target": "es5",
     "module": "commonjs",...
 }
}

使用 Visual Studio 时,需要重新启动 Visual Studio。

【讨论】:

    【解决方案4】:

    将 compileOnSave 添加到 tscnfig.json 将解决此问题。

    {
       "compileOnSave": true,
    
       "compilerOptions": {
         "target": "es5",
         "module": "commonjs",...
     }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-05-14
      • 2018-11-08
      • 2018-01-21
      • 2021-04-08
      • 2020-04-13
      • 1970-01-01
      • 2021-04-19
      • 2021-11-11
      • 2021-10-14
      相关资源
      最近更新 更多