构建消息 "ERROR in Cannot read property 'toLowerCase' of undefined"

ng build message "ERROR in Cannot read property 'toLowerCase' of undefined"

我正在使用 Azure DevOps YAML 管道 build/deploy 我的 Angular 9 应用程序。 YAML 包含一个 Powershell 脚本来构建它,如下所示

- powershell: |
    $angularBuildConfiguration = "MyBuildConfig";

    write-host "ng-build start";
    ng build --prod --aot --configuration $angularBuildConfiguration;
    write-host "ng-build end";

  workingDirectory: '$(Build.SourcesDirectory)\...'
  displayName: 'Build app - Angular app'

以上通过 Angular 构建,最后 returns 消息 "ERROR in Cannot read property 'toLowerCase' of undefined"。

我已验证 workingDirectory 和 angularBuildConfiguration 参数具有预期的值 - 我还用硬编码值替换了它们并获得了相同的结果。如果我在构建服务器上 运行 上面的 Powershell 脚本(YAML 脚本实际上 运行s 打开),在预期的文件夹中构建失败并显示相同的错误消息,但是如果我使用相同的构建我本地机器上的脚本成功构建

我不知道这是 ng 构建问题,还是我的 Angular 9 项目中有什么东西导致了错误 - 没有 'associated' 文件被标记为伴随错误信息

有没有人有什么想法?

在将字符串变量转换为小写时代码库中存在错误。 简单地说,它试图将 undefined 或 false 值转换为小写。

要使用小写JavaScript内置函数,变量必须是真值。

所以在代码库中搜索它,并像下面这样更新它。

If (variable) {
    variable = variable.toString().tolowercase();
}

这确实是 运行dom - toLowerCase 消息没有引用任何 javascript/typescript 代码 - 它一定是内部消息。我可以通过消除过程查明问题所在的唯一方法 - 即一次取出一批网页,直到我得到一个干净的产品编译 - 然后一个一个地工作以找到罪魁祸首。

存在导致问题的样式 - 我们替换了以下内容

.gridlines-left {
  border: 1px solid #c0c0c0;
  border-right-width: 0;
  border-top-width: 0;
  border-bottom-width: 0;
}

...与

.gridlines-left {
  border: 1px solid #c0c0c0;
  border-right-style: none;
  border-top-style: none;
  border-bottom-style: none;
}

...并且编译 运行 成功。我仍然不知道 how/why 因为我们有很多其他非常相似的样式并且使用相同的策略设置 border-right/left/bottom/top-width: 0 - 这可能与我们如何组合 css 有关类 - 某些样式可能会在编译时与其他样式发生冲突 - 谁知道呢,但现在一切正常并且自从

以来就没有出现过问题