Typescript TS5042 Build:选项“project”不能与命令行上的源文件混合

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35813033/
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-10-21 03:20:04  来源:igfitidea点击:

Typescript TS5042 Build: Option 'project' cannot be mixed with source files on a command line

typescriptvisual-studio-2015angular

提问by user1781272

I am receiving the following error across all typescript projects that I am trying run.

我在尝试运行的所有打字稿项目中都收到以下错误。

TS5042  Build: Option 'project' cannot be mixed with source files on a command line.

I have downloaded a free Typescript Angular2 template, ran it and this error immediately pops up.

我下载了一个免费的 Typescript Angular2 模板,运行它,这个错误立即弹出。

Has it got something to do with my global typescript installation?

它与我的全局打字稿安装有关吗?

采纳答案by user1781272

I have found a fix that works for me. I have more than one version of Visualstudio at c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\

我找到了一个对我有用的修复程序。我在 c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\ 有不止一个版本的 Visualstudio

Open v15.0 and copy the Typescript folder to the v14.0 folder.

打开 v15.0 并将 Typescript 文件夹复制到 v14.0 文件夹。

回答by Nathan Friend

The tsccommand can be run in two ways:

tsc命令可以通过两种方式运行:

  1. With a projectparameter, which points to the directory that contains a tsconfig.json. For example: tsc --project ./app. The location of the tsconfig.jsondetermines the set of files that should be included in the compilation. See here for more about the tsconfig.json: https://github.com/Microsoft/TypeScript/wiki/tsconfig.json
  2. With a list of files as the default parameter. For example: tsc MyFile1.ts MyFile2.ts MyFile3.ts.
  1. 带有一个project参数,该参数指向包含tsconfig.json. 例如: tsc --project ./app。的位置tsconfig.json决定了应该包含在编译中的文件集。有关更多信息,请参见此处tsconfig.jsonhttps: //github.com/Microsoft/TypeScript/wiki/tsconfig.json
  2. 以文件列表作为默认参数。例如:tsc MyFile1.ts MyFile2.ts MyFile3.ts

These two options are incompatible with each other because they both attempt to define which files should be compiled.

这两个选项彼此不兼容,因为它们都试图定义应该编译哪些文件。

What is the command you are using to compile your project? Or are you using an IDE that runs the build for you?

您用来编译项目的命令是什么?或者您使用的是为您运行构建的 IDE?

Here's the reference for the tsccompiler options.

这是tsc编译器选项的参考。

回答by Rahul Singh Bhadhoriya

i was getting same error but when removed every space in my folders name as shown in path from tsc compiler it now successfully builds.See also this GitHub issue.

我遇到了同样的错误,但是当删除我的文件夹名称中的每个空格时,如 tsc 编译器的路径所示,它现在成功构建。另见此GitHub 问题

回答by Horkin

The solution for me was pretty simple. I looked at the filepath for my project and realized one of the folder names in the file path had a space in it. When I renamed the folder without the space, TSC -p worked just fine. It seems like TSC, when parsing out command line args, splits it at spaces so it saw the part of my filepath name after the space as a file to compile.

对我来说,解决方案非常简单。我查看了我的项目的文件路径,并意识到文件路径中的一个文件夹名称中有一个空格。当我在没有空格的情况下重命名文件夹时,TSC -p 工作得很好。似乎 TSC 在解析命令行参数时将其拆分为空格,因此它将空格后的文件路径名称部分视为要编译的文件。

回答by Fernando Pérez Lara

You have to add "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe"to the visual studio code user settings.

您必须添加"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe"到 Visual Studio 代码用户设置。

回答by Constantino Jacob

Not use Powershell. Use the old command.com in your configuration.

不使用Powershell。在您的配置中使用旧的 command.com。

{
    "files.autoSave": "afterDelay",
    "terminal.integrated.shell.windows": "C:\WINDOWS\System32\cmd.exe"
}

回答by Marcos José Pérez Pérez

If could be of help I have a little update. As explained in the previous issues, after I've seen the problems with 1.8 I tried to uninstall it and reinstall 1.7 to continue to work to my projects, but even the installation was ok I had different problems compiling these asp.net 5 apps. I tried repairing vs, uninstalling and reinstalling 1.7 and 1.8 in any order without any changes. In the end I checked the directory C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript and I found that at the end of the uninstall of every version of typescript I have this

如果可以帮助我有一点更新。正如在之前的问题中所解释的,在我看到 1.8 的问题后,我尝试卸载它并重新安装 1.7 以继续为我的项目工作,但即使安装没问题,我在编译这些 asp.net 5 应用程序时也遇到了不同的问题。我尝试以任何顺序修复 vs,卸载并重新安装 1.7 和 1.8,没有任何更改。最后,我检查了目录 C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript,我发现在卸载每个版本的打字稿结束时我都有这个

search for this folder and deleteAt this point I tried to remove this directory completely and retried to uninstall typescript 1.7.6. and now it works fine. I tried doing this cleaning up and installing 1.8 beta, but I continue to have the same problem, but at least now I can work on asp.net 5 projects. I think that the problem rolling back to previous version was unable to overwrite at least the TypeScript.Tasks.dll generating an inconsistent behavior. Could be possibile that to make work nightly builds of 1.8

搜索此文件夹并删除此时我尝试完全删除此目录并重试卸载 typescript 1.7.6。现在它工作正常。我尝试清理并安装 1.8 beta,但我仍然遇到同样的问题,但至少现在我可以处理 asp.net 5 项目。我认为回滚到以前版本的问题至少无法覆盖产生不一致行为的 TypeScript.Tasks.dll。可能使每晚构建 1.8

and the error TS5042 solve. I hope this help you.

和错误 TS5042 解决。我希望这对你有帮助。