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

Azure DevOps CI流水线中node-prune安装后提示未找到的问题

解决Azure DevOps CI中node-prune未找到的问题

问题原因

用Go@0任务的get命令安装node-prune后,二进制文件会被放到$(GOPATH)/bin目录下,但Azure DevOps的Go任务执行环境默认不会把这个目录加入系统PATH,直接调用node-prune自然找不到可执行文件。

解决方法

方法1:直接指定node-prune的完整路径

修改Prune Node Modules任务,用$(GOPATH)/bin/node-prune作为自定义命令:

- task: Go@0
  displayName: Prune Node Modules
  inputs:
    command: 'custom'
    customCommand: '$(GOPATH)/bin/node-prune'
    arguments: '$(projectDirectory)'

方法2:将GOPATH/bin加入系统PATH

在安装node-prune后添加一个任务,把GOPATH/bin路径注入到环境变量中:

- task: GoTool@0
  displayName: Install Go
  inputs:
    version: '1.10' 

- task: Go@0
  displayName: Install Node-Prune
  inputs:
    command: 'get'
    arguments: 'github.com/tj/node-prune'

# 添加此任务,将GOPATH/bin加入PATH
- task: PowerShell@2
  displayName: Add GOPATH/bin to PATH
  inputs:
    targetType: 'inline'
    script: |
      echo "##vso[task.setvariable variable=PATH]$(GOPATH)/bin;$env:PATH"

- task: Go@0
  displayName: Prune Node Modules
  inputs:
    command: 'custom'
    customCommand: 'node-prune'
    arguments: '$(projectDirectory)'

方法3:改用npm安装node-prune(更适配Node项目)

既然是Node项目,直接通过npm全局安装node-prune,无需依赖Go环境,安装后可直接调用:

# 先安装Node.js(根据项目实际版本调整)
- task: NodeTool@0
  displayName: Install Node.js
  inputs:
    versionSpec: '16.x'

- task: CmdLine@2
  displayName: Install Node-Prune via npm
  inputs:
    script: 'npm install -g node-prune'

- task: CmdLine@2
  displayName: Prune Node Modules
  inputs:
    script: 'node-prune $(projectDirectory)'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 14:48:17