[英]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.