You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps中Angular流水线突发lint模块缺失错误的排查与解决

问题诊断与解决方案:Azure DevOps Ubuntu流水线Lint失败(找不到functions-have-names模块)

问题描述

本地Windows环境使用ng 14.2.0、node 16.15.0、eslint 14.1.2执行lint正常,但Azure DevOps Ubuntu自托管流水线执行相同版本时失败,核心报错:

Failed to load plugin '@angular-eslint/template' declared in '.eslintrc.json#overrides[0]': Cannot find module 'functions-have-names'

完整报错输出:

Starting: Linting
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.212.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /azp/_work/_temp/ee65254e-8ae2-489b-af62-a95cb725b90c.sh

Linting "caats-pwa"...
An unhandled exception occurred: Failed to load plugin '@angular-eslint/template' declared in '.eslintrc.json#overrides[0]': Cannot find module 'functions-have-names'
Require stack:
- /azp/_work/1/s/node_modules/set-function-name/index.js
- /azp/_work/1/s/node_modules/regexp.prototype.flags/implementation.js
- /azp/_work/1/s/node_modules/regexp.prototype.flags/index.js
- /azp/_work/1/s/node_modules/deep-equal/index.js
- /azp/_work/1/s/node_modules/aria-query/lib/elementRoleMap.js
- /azp/_work/1/s/node_modules/aria-query/lib/index.js
- /azp/_work/1/s/node_modules/@angular-eslint/eslint-plugin-template/dist/index.js
- /azp/_work/1/s/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
Referenced from: /azp/_work/1/s/.eslintrc.json
See "/tmp/ng-54uHxa/angular-errors.log" for further details.
##[error]Bash exited with code '1'.
Finishing: Linting

已固定核心工具版本,且从历史正常版本标签运行仍报错,排除代码/脚本变更问题,怀疑构建系统拉取了最新OS或依赖导致兼容性冲突。当前流水线YAML配置:

pool:
  name: Default
  vmImage: ubuntu-latest

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '16.15.0'
  displayName: 'Node.js installation'

- script: |
    npm install --location=project --force @angular/cli@~14.2.0
  displayName: 'Install Angular'

- script: |
    npm install --force
  displayName: 'Dependencies'

- script: |
    npx ng lint
    if [ $? -ne 0 ]; then
      exit 1
    fi
  displayName: 'Linting'

诊断方法

  • 检查模块是否存在:在流水线中添加步骤执行ls -la node_modules/functions-have-names,确认该模块是否真的缺失。
  • 分析依赖树:执行npm ls functions-have-names,查看该模块的间接依赖链路,确认是否存在版本不兼容或依赖断裂。
  • 对比锁文件差异:将本地package-lock.json与流水线生成的版本对比,重点查看functions-have-names、set-function-name、regexp.prototype.flags等上游依赖的版本是否一致。

解决方案

方案1:强制安装缺失依赖

在依赖安装步骤后,手动添加functions-have-names的安装命令,确保模块被正确拉取:
修改后的依赖步骤:

- script: |
    npm install --force
    npm install --force functions-have-names
  displayName: 'Dependencies'

方案2:锁定依赖版本

将functions-have-names及关联依赖的稳定版本写入package.json的devDependencies,避免npm自动拉取不兼容版本:

{
  "devDependencies": {
    "functions-have-names": "^1.2.3",
    "set-function-name": "^2.0.1",
    "regexp.prototype.flags": "^1.5.1"
  }
}

更新后重新生成package-lock.json并提交,流水线执行npm install时会遵循锁定版本。

方案3:清理流水线缓存

Ubuntu流水线可能存在缓存的旧依赖导致冲突,添加清理步骤确保依赖完全重装:

- script: |
    rm -rf node_modules
    rm package-lock.json
    npm cache clean --force
  displayName: 'Clean dependencies and cache'

将此步骤放在npm install之前执行。

方案4:指定Ubuntu镜像版本

当前使用的ubuntu-latest可能更新到了新OS版本(如Ubuntu 22.04),与旧版依赖存在兼容性问题,尝试指定稳定旧版本:

pool:
  name: Default
  vmImage: 'ubuntu-20.04'

内容的提问来源于stack exchange,提问作者Cee McSharpface

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 21:08:26