Azure DevOps 管道上出现 TypeScript 构建错误的 Angular 应用程序 - 错误 TS2677

Len*_*rri 6 typescript lodash azure-devops azure-pipelines angular

仅在 DevOps 管道上的Npm@1任务期间发生以下错误。该应用程序在本地构建得很好。完全没有错误。

Angular CLI 版本是 8.3.29,TypeScript 版本是 3.5.3。

它正在执行这个自定义命令:

run build:artifact
Run Code Online (Sandbox Code Playgroud)

该自定义命令在以下位置指向此内容package.json

ng build --configuration=artifact
Run Code Online (Sandbox Code Playgroud)

抛出的错误是:

../node_modules/@types/lodash/common/lang.d.ts:577:74 - 错误 TS2677:类型谓词的类型必须可分配给其参数的类型。

来自管道的完整日志:

Starting: Angular Build
==============================================================================
Task         : npm
Description  : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
Version      : 1.202.0
Author       : Microsoft Corporation
Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/package/npm
==============================================================================
C:\Windows\system32\cmd.exe /D /S /C "C:\hostedtoolcache\windows\node\14.15.0\x64\npm.cmd --version"
6.14.8
C:\Windows\system32\cmd.exe /D /S /C "C:\hostedtoolcache\windows\node\14.15.0\x64\npm.cmd config list"
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.14.8 node/v14.15.0 win32 x64"

; environment configs
prefix = "C:\\npm\\prefix"
userconfig = "D:\\a\\1\\npm\\11507.npmrc"

; globalconfig C:\npm\prefix\etc\npmrc
cache = "C:\\npm\\cache"

; node bin location = C:\hostedtoolcache\windows\node\14.15.0\x64\node.exe
; cwd = D:\a\1\s\client-site-spa
; HOME = C:\Users\VssAdministrator
; "npm config ls -l" to show all defaults.

C:\Windows\system32\cmd.exe /D /S /C "C:\hostedtoolcache\windows\node\14.15.0\x64\npm.cmd run build:artifact"

ERROR in ../node_modules/@types/lodash/common/lang.d.ts:577:74 - error TS2677: A type predicate's type must be assignable to its parameter's type.
  Type 'EmptyObjectOf<T>' is not assignable to type 'T'.
    'EmptyObjectOf<T>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'object'.
      Type 'EmptyObject<T>' is not assignable to type 'T'.
        'EmptyObject<T>' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'object'.

577         isEmpty<T extends object>(value: T | null | undefined): value is EmptyObjectOf<T> | null | undefined;
                                                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project-angular@0.0.0 build:artifact: `ng build --configuration=artifact`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the project-angular@0.0.0 build:artifact script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\npm\cache\_logs\2022-08-17T15_41_17_869Z-debug.log

> project-angular@0.0.0 build:artifact D:\a\1\s\client-site-spa
> ng build --configuration=artifact
Run Code Online (Sandbox Code Playgroud)

您知道如何查找抛出此错误的位置吗?

ng build --configuration=artifact当我在具有匹配的 node\npm 版本的开发盒上手动运行相同的命令 [ ] 时,不会发生错误:

在此输入图像描述

#######

按照 MikeOne 建议删除node_modules文件夹和package-lock.json文件后,我能够从本地管道中得到相同的错误...但是它仍然没有告诉我们在哪个文件中发生了错误。:|

包锁

#######

没有迹象表明此错误发生在我自己的源代码中的任何地方。这会是它本身的错误吗lodash?我正在使用截至目前可用的最新版本4.17.21

在此输入图像描述

#######

这似乎是 TypeScript 编译器正在咆哮的接口成员......但是,我没有在代码中的任何地方调用它。

在此输入图像描述

Jou*_*usi 15

最近的一次提交破坏了这个包。该问题正在他们的 Github上进行跟踪,但与此同时我们可以坚持使用以前的@types/lodash版本4.14.182