【问题标题】:Azure DevOps Build pipeline `npm install` failing on node-gypAzure DevOps 构建管道“npm install”在 node-gyp 上失败
【发布时间】:2022-01-16 19:17:22
【问题描述】:

我们有一个 CD/CI Azure Devops 构建管道,该管道已开始因nodejs/node-gyp 而失败。

  • error gyp info using node-gyp@3.8.0
  • error gyp info using node@16.13.0 | win32 | x64

我们的构建管道没有任何变化,我们使用的池是:

pool:
  vmImage: 'windows-latest'

仍然映射到windows-2019https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml。

当我们在 YAML 文件中执行以下任务时,管道失败:

- task: Npm@1
  displayName: 'npm install'
  inputs:
    command: 'install'
    workingDir: 'FrontEnd'
    verbose: true

日志文件:

error gyp ERR! UNCAUGHT EXCEPTION
error gyp ERR! stack Error: spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\15.0\Bin\MSBuild.exe ENOENT
error gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
error gyp ERR! stack     at onErrorNT (node:internal/child_process:477:16)
error gyp ERR! stack     at processTicksAndRejections (node:internal/process/task_queues:83:21)
error gyp ERR! System Windows_NT 10.0.17763
error gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\a\\1\\s\\Presentation\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
error gyp ERR! cwd D:\a\1\s\FrontEnd\node_modules\node-sass
error gyp ERR! node -v v16.13.0
error gyp ERR! node-gyp -v v3.8.0
error gyp ERR! This is a bug in `node-gyp`.
error gyp ERR! Try to update node-gyp and file an Issue if it does not help:
error gyp ERR!     <https://github.com/nodejs/node-gyp/issues>
error Build failed with error code: 7
verbose exit 1

##[error]Error: Npm failed with return code: 1

【问题讨论】:

    标签: node.js npm azure-devops yaml


    【解决方案1】:

    Azure 自动更新了它正在使用的节点版本,也将所需的 node-gyp 版本向前推,这导致我们所有的构建都失败了。它推送到的版本是:

    • npm@8.1.0
    • node@v16.13.0

    添加 task: NodeTool@0 将 Node 版本设置为最后通过的版本,对我们来说是:

    • npm@6.14.15
    • node@14.18.1

    结束代码如下:

    - task: NodeTool@0
      inputs:
        versionSpec: '14.x'
        
    - task: Npm@1
      displayName: 'npm install'
      inputs:
        command: 'install'
        workingDir: 'FrontEnd'
        verbose: true
    

    重新运行管道后,它再次工作并产生人工制品。

    【讨论】:

      【解决方案2】:

      我们遇到的 npm/node 版本问题指向 node-gyp 作为罪魁祸首,如此处所示。如果特定组件异常下未显示冲突版本,则在运行 npm install 时,会在用户代理下显示 npm/node 版本

      在 npm install 任务下,用户代理显示为:

      user-agent = "npm/6.14.15 node/v16.13.0 win32 x64"

      运行“windows-latest”图像时。

      使用上一个答案中的节点工具,上面它变为:

      user-agent = "npm/6.14.15 node/v14.18.1 win32 x64"

      这个问题类似于Azure DevOps Pipeline NPM install task fails with node-gyp build error

      【讨论】:

        【解决方案3】:

        对于那些不使用 yaml 和经典编辑器的人:

        Node.js tool installer settings

        【讨论】:

        • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center。
        【解决方案4】:

        对于经典编辑器用户:

        • 转到管道
        • 点击所需管道附近的编辑
        • 在 npm install 任务之前添加 Node.js 工具安装程序任务
        • 版本规范:14.x
        • 保存管道

        【讨论】:

          猜你喜欢
          • 2012-08-20
          • 1970-01-01
          • 2015-03-28
          • 2016-05-19
          • 2020-09-11
          • 1970-01-01
          • 2019-04-05
          • 1970-01-01
          • 2014-12-04
          相关资源
          最近更新 更多