I'm fairly new to Azure Pipelines and CI/CD in general. My pipeline needs to install node, then PNPM, the dependencies, and then run a build script.
Here's my pipeline 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"
The first five steps all run without a hitch. But then during the "Build UI" step, I get the following:
========================== 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
> pov-ui@1.0.0 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
As you can see, I've added some debug lines to confirm that the current version of node is the one I installed earlier (v20.12.2). But as soon as the PNPM script starts to run, it seems to fall back to v16.20.2.
Can anyone help me understand why PNPM is using a node version other than the one I explicitly installed?
Note: I realise the documentation for PNPM suggests using Corepack to install PNPM, rather than the npm install -g pnpm
approach I've gone with here. But whenever I used Corepack, it was giving its own inscrutable errors. All the suggested fixes for that particular issue suggested updating to a newer version of node, which didn't help me as I thought I was using the current LTS version. Now that I discover I'm not, the error's making more sense.
On ubuntu-latest
agent, it already has node.js
version 18.20.2
by default(link here).
Checked on my side, with your npm install -g pnpm
task, it can install 9.0.6
version PNPM, and pipeline can work fine:
The current version of Node.js is v16.20.2
It could happen that you have v16.20.2
node.js defined somewhere, eg .npmrc
.
It will fetch the version v16.20.2
in this case:
Please check the code if v16.20.2
node.js is defined, fix it or remove it for a check. In addition, please temporally remove the cache
task to avoid code restore, you can add it back once pipeline is working.