Javascript 继续以代码 1 退出“tsc.exe”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37350183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 20:13:56  来源:igfitidea点击:

Keep getting "tsc.exe" exited with code 1

javascripttypescriptvisual-studio-2015

提问by Frank Cannon

As soon as I add a tsconfig.json file to my Visual Studio 2015 web solution I get the above error.

一旦我将 tsconfig.json 文件添加到我的 Visual Studio 2015 Web 解决方案,我就会收到上述错误。

Also this stops the compiler from re-generating js files even when I set "compileOnSave": true.

即使我设置了“compileOnSave”:true,这也会阻止编译器重新生成js文件。

When I double click the error it takes me into the Microsoft.Typescript.Targets file which contains a lot of issues such as Unknown Item Group "TypeScriptCompile". In the error list these appear as warnings but they are there whether I have a tsconfig.json file or not.

当我双击错误时,它会将我带入 Microsoft.Typescript.Targets 文件,该文件包含许多问题,例如未知项目组“TypeScriptCompile”。在错误列表中,这些显示为警告,但无论我是否有 tsconfig.json 文件,它们都在那里。

Is there any way of solving it or getting more information on what the problem is?

有没有办法解决它或获取有关问题所在的更多信息?

回答by Dmitry Vasiliev

Install these 2 NuGet packages:

安装这两个 NuGet 包:

Microsoft.TypeScript.MSBuildand Microsoft.TypeScript.Compiler

Microsoft.TypeScript.MSBuildMicrosoft.TypeScript.Compiler

It updates your project with MSBuild task definition and TS compiler and solves the compilation issue

它使用 MSBuild 任务定义和 TS 编译器更新您的项目并解决编译问题

回答by Mohamed Badr

For me installing TypeScript for Visual Studiofixed it, although TypeScript was already installed globally on my machine via npm

对我来说,为 Visual Studio安装TypeScript修复了它,尽管 TypeScript 已经通过以下方式在我的机器上全局安装npm

回答by thoean

I am using a .NET Core 1.0 project and ran into the same situation of getting a tsc.exereturn code of 1. My problem was an invalid tsconfig.json. However, msbuild does not provide those details.

我正在使用 .NET Core 1.0 项目并遇到相同的情况,tsc.exe返回码为 1。我的问题是无效的tsconfig.json. 但是,msbuild 不提供这些详细信息。

The easiest way to find out is to enable detailed output in Visual Studio -> Tools -> Options -> Projects and Solutions -> Build and Run -> MSBuild project build output verbosity. Change this to Detailed. After compiling, find tsc.exein the output window to see the actual error tsc was throwing.

找出答案的最简单方法是在Visual Studio -> Tools -> Options -> Projects and Solutions -> Build and Run -> MSBuild project build output verbosity. 将此更改为Detailed. 编译后,tsc.exe在输出窗口中找到以查看 tsc 抛出的实际错误。

回答by Ilya Chernomordik

I had this problem as well after using some standard Angular / Typescript tutorials. The solution was as simple as to update typescript in Visual Studio.

在使用了一些标准的 Angular / Typescript 教程后,我也遇到了这个问题。解决方案就像在 Visual Studio 中更新打字稿一样简单。

For some reason the default is now 1.8.4. and it does not allow you to automatically update it from Visual Studio Extensions and does not say it is out of date. You just download it from hereand install newest version yourself. Download link may change in the future of course.

出于某种原因,默认值现在是 1.8.4。它不允许您从 Visual Studio 扩展中自动更新它,也不会说它已过时。您只需从这里下载并自行安装最新版本。当然,下载链接将来可能会更改。

P.S. I think the problem was caused by the fact that some options that did not exist in older compiler were used.

PS 我认为问题是由于使用了旧编译器中不存在的一些选项造成的。

回答by fiat

This worked for TeamCity build server with Visual Studio 2015 when I had upgraded a project from Typescript 1.8to 2.3

这个工作对构建的TeamCity服务器与Visual Studio 2015年时,我已经升级,从打字稿的一个项目1.8,以2.3

  • Install package Microsoft.TypeScript.MSBuild
  • Update *.csprojas follows

    1. Upgrade TypeScriptToolsVersionto 2.3(in this case)
    2. Remove two lines of Import Projectthat referred to Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets
  • 安装包 Microsoft.TypeScript.MSBuild
  • 更新*.csproj如下

    1. 升级TypeScriptToolsVersion2.3(在这种情况下)
    2. 删除Import Project提到的 两行Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets

Note

笔记

  • Removing the importelements is important as they are referring to TypeScript installed in the %PROGRAMFILES(X86)%folder.
  • Installing the package adds importelements that reference the packagesfolder - making your build more portable
  • 删除import元素很重要,因为它们指的是安装在%PROGRAMFILES(X86)%文件夹中的TypeScript 。
  • 安装包会添加import引用packages文件夹的元素- 使您的构建更加便携

回答by Jernej Novak

I had same issue and what happened in my case is that the file .ts was in the project but it was not on file system. Something like this missing file on filesystem. So removed the file from project and everything started to work again.

我有同样的问题,在我的情况下发生的事情是文件 .ts 在项目中,但不在文件系统上。像这样的东西文件系统上缺少文件。所以从项目中删除了文件,一切又开始工作了。

回答by Jon Crowell

Installing Microsoft.Typescript.MsBuild fixed the issue for me, but only if I installed the penultimate version. The current (stable) version is 2.0.6, and after I installed it, the issue persisted. When I reverted to 1.8.11, the issue went away.

安装 Microsoft.Typescript.MsBuild 为我解决了这个问题,但前提是我安装了倒数第二个版本。当前(稳定)版本为2.0.6,安装后问题依旧。当我恢复到 1.8.11 时,问题就消失了。

回答by Nirbhay Jha

I had the same issue. Fixed it by removing the following from the project file

我遇到过同样的问题。通过从项目文件中删除以下内容来修复它

<TypeScriptToolsVersion>2.0</TypeScriptToolsVersion>

回答by Josh M.

Move all files within C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Typ??escriptinto some new folder (e.g. backup), then try again. This will cause MSBuild to select tsc.exefrom within the appropriately versioned folder instead of using the one in the C:\Program Files (x86)\Microsoft SDKs\TypeScript.

将其中的所有文件移动C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Typ??escript到某个新文件夹(例如backup),然后重试。这将导致 MSBuildtsc.exe从适当版本的文件夹中进行选择,而不是使用C:\Program Files (x86)\Microsoft SDKs\TypeScript.

回答by perlyking

We are using npmand angular-clioutside VS to transpile our typescript. I ran into the problem described above on the only dev box that had the Web Essentials extension loaded. After trying installing, and then uninstalling the MS nugets and TypeScript extension described above to no avail, uninstalling Web Essentials finally did the trick.

我们在 VS 之外使用npmangular-cli转换我们的打字稿。我在唯一加载了 Web Essentials 扩展的开发箱上遇到了上述问题。在尝试安装,然后卸载上述 MS nugets 和 TypeScript 扩展无济于事后,卸载 Web Essentials 终于成功了。