【问题标题】:vs code typescript compile does nothingvs code typescript compile什么都不做
【发布时间】:2015-11-09 12:14:34
【问题描述】:

我安装了 VS Code 来尝试一下。我在 .ts 文件上按 Ctrl+Shift+B。第一次,它要求我设置一个构建任务,我做到了。现在,我再次构建,它什么也没做。我没有收到任何错误或警告,但也没有 .js 文件。我错过了什么?

tasks.json

{
    "version": "0.1.0", 
    // The command is tsc. Assumes that tsc has been installed using npm install -g typescript 
    "command": "tsc",
    // The command is a shell script 
    "isShellCommand": true,
    // Show the output window only if unrecognized errors occur. 
    "showOutput": "silent",
    // args is the program to compile. 
    "args": ["app.ts"],
    // use the standard tsc problem matcher to find compile problems 
    // in the output. 
    "problemMatcher": "$tsc"
}

tsconfig.json

{
    "compilerOptions": { 
        "target" : "ESS",
        "module": "amd",
        "sourceMap": true 
    } 
}

【问题讨论】:

  • 您能否提供您的 tsconfig 和 tasks.json 文件的外观。您需要正确设置这两个文件才能使其正常工作。查看本文以了解正确的步骤和配置。 blogs.msdn.com/b/typescript/archive/2015/04/30/…
  • 我看过那篇文章。我没有 tsconfig.json 文件。这是必需的吗?
  • tasks.json: { "version": "0.1.0", // The command is tsc. Assumes that tsc has been installed using npm install -g typescript "command": "tsc", // The command is a shell script "isShellCommand": true, // Show the output window only if unrecognized errors occur. "showOutput": "silent", // args is the program to compile. "args": ["app.ts"], // use the standard tsc problem matcher to find compile problems // in the output. "problemMatcher": "$tsc" }
  • tsconfig.json { "compilerOptions": { "target" : "ESS", "module": "amd", "sourceMap": true } }

标签: typescript visual-studio-code


【解决方案1】:

您是否运行过“npm install -g typescript”?查看tasks.json中的注释

【讨论】:

    【解决方案2】:

    每当我在 Visual Studio Code 中的任何任务出现问题时,我都会更改输出模式:

    "showOutput": "always",
    

    现在我会得到一个输出窗口,即使问题匹配器没有检测到问题。你会在这里看到任何问题。一切正常后,将其切换回“静音”。

    潜在问题...

    你目前的目标是ESS,我想你可能想要ES5(注意五个)。

    您应该在窗口左下角的警告三角形图标旁边看到1

    【讨论】:

    • 感谢您修复我的格式。我不知道该怎么做。我更改为 ES5,它确实修复了添加 tsconfig.json 时遇到的错误。但是它没有建立。我将输出切换为“始终”。这表明没有找到 tsc 。我也安装了 VisualStudio,所以 tsc 在某个地方。我想我必须以某种方式将它们连接起来。是时候做更多的搜索了......
    • 我进入 tsconfig.json 并将完全限定的路径放入 tsc.exe 而不是“tsc”,现在它可以编译了。非常感谢您的帮助!
    • 嗨,Shaun - 很高兴它有帮助 - 您还可以更新 PATH 变量以包含您的 tsc 路径,这意味着您不必在任何地方都使用完整路径。
    猜你喜欢
    • 2021-11-17
    • 2017-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-08
    • 2016-12-24
    • 2017-04-18
    • 2011-08-03
    相关资源
    最近更新 更多