We have a CD/CI Azure Devops build pipeline that has started failing for nodejs/node-gyp
.
error gyp info using [email protected]
error gyp info using [email protected] | win32 | x64
Nothing about our build pipeline has changed, the pool we use is:
pool:
vmImage: 'windows-latest'
Which is still mapped to windows-2019
https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml.
The pipeline fails when we hit the following task in the YAML file:
- task: Npm@1
displayName: 'npm install'
inputs:
command: 'install'
workingDir: 'FrontEnd'
verbose: true
Log file:
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 one rrorNT (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
CodePudding user response:
Azure auto updated the version of node it was using, pushing the required version of node-gyp forward too, this lead to all of our builds failing. The versions it pushed to were:
Add task: NodeTool@0
to set the Node version to the last passed version which for us was:
The end code looks like this:
- task: NodeTool@0
inputs:
versionSpec: '14.x'
- task: Npm@1
displayName: 'npm install'
inputs:
command: 'install'
workingDir: 'FrontEnd'
verbose: true
After re-running the pipeline it works again and produces artefacts.
CodePudding user response:
The issue we had with npm/node versions pointed to node-gyp as the culprit as shown here. If the conflicting versions are not shown under the particular component exception, the npm/node versions are revealed under the user-agent when npm install is running
Under the npm install task the user agent is shown as:
user-agent = "npm/6.14.15 node/v16.13.0 win32 x64"
when running the 'windows-latest' image.
Using the node tool in the previous answer, the above it changes to:
user-agent = "npm/6.14.15 node/v14.18.1 win32 x64"
This question is similar to Azure DevOps Pipeline NPM install task fails with node-gyp build error