简体   繁体   English

Angular 应用程序与 typescript 在 Azure DevOps 管道上构建错误 - 错误 TS2677

[英]Angular app with typescript build error on Azure DevOps pipeline - error TS2677

The following error is happening only during Npm@1 task on the DevOps pipeline.以下错误仅在 DevOps 管道上的Npm@1任务期间发生。 The app builds just fine locally.该应用程序在本地构建得很好。 No errors at all.完全没有错误。

Angular CLI version is 8.3.29 and TypeScript version is 3.5.3. Angular CLI 版本为 8.3.29,TypeScript 版本为 3.5.3。

It's executing this custom command:它正在执行这个自定义命令:

run build:artifact

and that custom command points to this in package.json :并且该自定义命令在package.json中指向此:

ng build --configuration=artifact

The error being thrown is:抛出的错误是:

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

Full log from the pipeline:来自管道的完整日志:

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://docs.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

Do you know how to hunt down where this error is being thrown?您知道如何找出引发此错误的位置吗?

When I run the same command [ ng build --configuration=artifact ] manually on my dev box with matching node\npm versions, no error happens:当我在具有匹配 node\npm 版本的开发盒上手动运行相同的命令 [ ng build --configuration=artifact ] 时,不会发生错误:

在此处输入图像描述

####### #######

After deleting the node_modules folder and package-lock.json file as MikeOne suggested, I was able to get the same error from the pipeline locally... however it still doesn't tell us in what file the error is happening.按照 MikeOne 的建议删除node_modules文件夹和package-lock.json文件后,我能够从本地管道中得到相同的错误......但是它仍然没有告诉我们错误发生在哪个文件中。 :| :|

包锁

####### #######

There's no indication this error is happening anywhere on my own source code.没有迹象表明这个错误发生在我自己的源代码的任何地方。 Would this be an error from lodash itself?这会是lodash本身的错误吗? I'm using the latest version available as of now 4.17.21 .我正在使用截至目前可用的最新版本4.17.21

在此处输入图像描述

####### #######

This seems to be the interface member that the TypeScript compiler is barking about... however, I'm not calling it anywhere on my code.这似乎是 TypeScript 编译器正在咆哮的接口成员......但是,我没有在我的代码的任何地方调用它。

在此处输入图像描述

A recent commit has broken the package. 最近的一次提交破坏了 package。 The issue is being tracked ontheir Github , but in the meantime we could stick to the previous version of @types/lodash which is 4.14.182 .该问题正在他们的 Github上进行跟踪,但同时我们可以坚持使用@types/lodash的先前版本,即4.14.182

The lines that cause errors are 577:74 It will work if you make it as a comment.导致错误的行是 577:74 如果您将其作为注释,它将起作用。

I faced the same error when I was updating the npm-check version from 5.9.0 to 6.0.1当我将 npm-check 版本从 5.9.0 更新到 6.0.1 时,我遇到了同样的错误

If you notice the error:如果您注意到错误:

/node_modules/@types/lodash/common/lang.d.ts:577:74

it occurs because of @types/lodash package.这是因为@types/lodash package。 You can always check the tree structure of the package by following command:您始终可以通过以下命令检查 package 的树结构:

npm list <package-name> npm list @types/lodash npm list <package-name> npm list @types/lodash

I got following output:我得到了关注 output:

└─┬ npm-check@6.0.1 └─┬ callsite-record@4.1.4 └── @types/lodash@4.14.185 └─┬ npm-check@6.0.1 └─┬ callsite-record@4.1.4 └── @types/lodash@4.14.185

so it clearly tells, it happens because of npm-check version update.所以它清楚地表明,这是因为 npm-check 版本更新而发生的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于Angular的Azure DevOps构建管道并且无法执行构建脚本节点错误 - Azure DevOps build pipeline for Angular and Failed to exec build script Node error 有没有办法在构建 Angular 应用程序时在 Azure CI 构建管道中提供 environment.prod.ts 文件? - Is there a way to provide environment.prod.ts file in a Azure CI build pipeline while building an Angular App? npm 在 Azure 使用 Angular 项目构建管道时出错 - Error on npm build in Azure build pipeline with Angular project 错误 TS2307:找不到模块“rxjs/Operators”Azure DevOps Angular 8 - error TS2307: Cannot find module 'rxjs/Operators' Azure DevOps Angular 8 错误 TS1005: &#39;;&#39; 预期的。 Node_modules 中的 TypeScript Angular 6 For First Build 错误 rxjs - Error TS1005: ';' expected. TypeScript Angular 6 For First Build error rxjs inside node_modules 通过 Azure 管道构建.Net 5 web 应用程序(带有 Angular)时出错 - Error while building .Net 5 web app(with Angular) through Azure Pipeline Angular 11.2.6 或 Typescript TS2345 错误 - Angular 11.2.6 or Typescript TS2345 error Angular 2 Typescript编译错误TS2304? - Angular 2 Typescript compilation error TS2304? Angular2构建错误TS2305 - Angular2 build error TS2305 Azure devops中的角项目CI给出错误“发布构建工件失败,并显示错误:” - Angular project CI in azure devops giving error 'Publishing build artifacts failed with an error: '
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM