首页 > 解决方案 > Angular-cli 项目,托管在 Visual Studio Core 2.2 Web Api 项目中,随机编译失败

问题描述

我有一个基于 API 模板的 Visual Studio 2017 ASP.NET Core 2.2 项目。在 Api 项目中,我创建了一个新的基于 angular-cli 的 Web 应用程序。

Visual Studio Build 无法随机编译。构建失败。然后我再次编译而不更改任何内容,构建成功完成。如果我再次构建,它现在将始终编译但带有警告,并且突然它会再次开始失败并出现相同的错误并重复。

当它失败时,我会收到 24 个与此类似的构建错误。它在nodes_modules 下打包文件夹。

TS2420  Build:Class 'MockMediaQueryList' incorrectly implements interface 'MediaQueryList'. C:\somePath\node_modules\@angular\flex-layout\core\typings\match-media\mock\mock-match-media.d.ts

当它编译时,我有 8 个这样的警告:

C:\somePath\node_modules\@angular\flex-layout\core\typings\match-media\mock\mock-match-media.d.ts(62,22): error TS2420: Build:Class 'MockMediaQueryList' incorrectly implements interface 'MediaQueryList'.

我不知道在编译时对 node_modules 下的文件进行任何操作的任何操作。MsBuild 应该完全忽略 angular-cli 应用程序,但显然不是。

在“项目属性”->“Typescript build”下,我选择了“使用最新可用”并删除了“启用”复选框中的复选标记。

这是我的 project.csproj 文件

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
  <TargetFramework>netcoreapp2.2</TargetFramework>
  <IsServiceFabricServiceProject>True</IsServiceFabricServiceProject>
  <ServerGarbageCollection>True</ServerGarbageCollection>
  <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
  <TargetLatestRuntimePatch>False</TargetLatestRuntimePatch>
  <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
   <Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
   <Folder Include="wwwroot\" />
 </ItemGroup>
 <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.ServiceFabric.AspNetCore.Kestrel" Version="3.3.617" />
 </ItemGroup>
    <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptTarget>ES2015</TypeScriptTarget>
    <TypeScriptJSXEmit>None</TypeScriptJSXEmit>
    <TypeScriptModuleKind>ES6</TypeScriptModuleKind>
    <TypeScriptCompileOnSaveEnabled>False</TypeScriptCompileOnSaveEnabled>
    <TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
    <TypeScriptRemoveComments>True</TypeScriptRemoveComments>
    <TypeScriptOutFile />
    <TypeScriptOutDir />
    <TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations>
    <TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
    <TypeScriptSourceMap>True</TypeScriptSourceMap>
    <TypeScriptMapRoot />
    <TypeScriptSourceRoot />
  </PropertyGroup>
</Project>

标签: visual-studioasp.net-coreangular-cli

解决方案


问题已通过升级到最新版本解决

npm install @angular/flex-layout@latest 

推荐阅读