Azure DevOps, ENOENT issue with NPM Caching

791 Views Asked by At

I have this issue on build task the second time I run the build pipeline without any changement in my code:

ENOENT: no such file or directory, open 'D:\a\1\s\src\client\node_modules.cache\angular-build-fonts\content-v2\sha512\20\92\5b910157b4a6180d92f5ea0232867edfcf77ed4095350c1a5dcc19600396b2386935fce40ebe9e2cf1d4c5051f07a3f5090c57e7b8f33f9cdae8fa62c139' npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] build: ng build --configuration=production --prod --build-optimizer --optimization --aot npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

As the first build worked correctly, I'm confident to think that the issue comes from the Azure Dev Ops caching. It's like the cache task doesn't save every thing from node_modules.

Here is the YML script (note, I use the classic editor):

variables:
  NPM_PACKAGES: '$(Build.SourcesDirectory)/src/client/node_modules'

steps:
- task: Cache@2
  displayName: 'Cache npm'
  inputs:
    key: 'npm | $(Agent.OS) | 5 | $(Build.SourcesDirectory)\src\client\package-lock.json'
    path: '$(NPM_PACKAGES)'
    cacheHitVar: 'NPM_CACHE_RESTORED'

- task: Npm@1
  displayName: 'install -g [email protected]'
  inputs:
    command: custom
    verbose: false
    customCommand: 'install -g [email protected]'

- task: Npm@1
  displayName: 'npm ci'
  inputs:
    command: ci
    workingDir: src/client
    verbose: false
  condition: ne(variables.NPM_CACHE_RESTORED, 'true')

- task: Npm@1
  displayName: 'run build'
  inputs:
    command: custom
    workingDir: src/client
    verbose: false
    customCommand: 'run build --prod'

Note: I read that it's better to put in cache the cache folder than node_modules (https://docs.npmjs.com/cli/v8/commands/npm-cache) but not sure where is it. I added a task npm cache verify to have more information, but still get There is a cache miss. return by post cache task, so I understood that C:\npm\cache is not found. Where is the npm cache folder on Azure Dev Ops? $(Pipeline.Workspace)/.npm (source: https://learn.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#nodejsnpm) doesnt work either.

What do you suggest?

enter image description here

0

There are 0 best solutions below