Azure pipelines 节点版本差异

问题描述 投票:0回答:1

总体而言,我对 Azure Pipelines 和 CI/CD 相当陌生。我的管道需要安装节点,然后安装 PNPM、依赖项,然后运行构建脚本。

这是我的管道 YAML:

trigger:
  - none

pool:
  vmImage: ubuntu-latest

variables:
  pnpm_config_cache: $(Pipeline.Workspace)/.pnpm-store

steps:
  - task: UseNode@1
    inputs:
      version: "20.x"
    displayName: "Install Node.js"

  - task: Cache@2
    inputs:
      key: 'pnpm | "$(Agent.OS)" | ./src/ui/pnpm-lock.yaml'
      path: $(pnpm_config_cache)
    displayName: Cache pnpm

  - script: npm install -g pnpm
    displayName: "Install PNPM globally"

  - script: pnpm config set store-dir $(pnpm_config_cache)
    displayName: "Setup PNPM caching"

  - script: |
      cd src/ui
      pnpm install
    displayName: "Install PNPM packages"

  - script: |
      cd src/ui
      echo Node version
      node -v
      echo PNPM version
      pnpm -v
      pnpm fastbuild
    displayName: "Build UI"

前五个步骤都顺利进行。但在“构建 UI”步骤中,我得到以下信息:

========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/8e8e15dd-3e1b-4d6f-abe1-a994bcc1669a.sh
Node version
v20.12.2
PNPM version
9.0.6

> [email protected] fastbuild /home/vsts/work/1/s/src/ui
> pnpm lib && gulp build:fast --target=integration

ERROR: This version of pnpm requires at least Node.js v18.12
The current version of Node.js is v16.20.2
Visit https://r.pnpm.io/comp to see the list of past pnpm versions with respective Node.js version support.
 ELIFECYCLE  Command failed with exit code 1.

##[error]Bash exited with code '1'.
Finishing: Build UI

如您所见,我添加了一些调试行来确认当前版本的节点是我之前安装的版本(v20.12.2)。但一旦 PNPM 脚本开始运行,它似乎就会回退到 v16.20.2。

任何人都可以帮助我理解为什么 PNPM 使用我明确安装的节点版本之外的节点版本吗?


注意:我意识到 PNPM 的文档建议使用 Corepack 来安装 PNPM,而不是我在这里使用的

npm install -g pnpm
方法。但每当我使用 Corepack 时,它都会给出自己难以理解的错误。针对该特定问题的所有建议的修复都建议更新到较新版本的节点,这对我没有帮助,因为我认为我正在使用当前的 LTS 版本。现在我发现我不是,这个错误就更有意义了。

node.js continuous-integration azure-pipelines pnpm corepack
1个回答
0
投票

ubuntu-latest
代理上,默认已经有
node.js
版本
18.20.2
(链接这里)。

enter image description here

在我这边检查过,通过你的

npm install -g pnpm
任务,它可以安装
9.0.6
版本的PNPM,并且管道可以正常工作:

enter image description here

Node.js 当前版本是 v16.20.2

您可能在某处定义了

v16.20.2
node.js,例如
.npmrc

enter image description here

在这种情况下它将获取版本

v16.20.2

enter image description here

请检查代码是否定义了

v16.20.2
node.js,修复它或删除它以进行检查。

© www.soinside.com 2019 - 2024. All rights reserved.