I’m having a really frustrating issue with my Angular project builds in Azure DevOps. About half of my builds are crashing with npm error code 134. It’s weird because I’m building the exact same code with the same pipeline configuration.
I’m using Angular CLI to build my project. The npm script runs ng build --production from my package.json. The strange part is that VS2017 and VS2019 hosted agents fail almost every time, but Windows container agents only fail about 50% of the time. This makes me think it’s something with the hosted environment itself.
Both working and failing builds use the same npm task version and npm 6.8. I tested with an on-premise build agent and it works fine there. Has anyone else run into this intermittent build failure issue?
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! [email protected] build: `ng build --production`
npm ERR! Exit status 134
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.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\npm\cache\_logs\2023-debug.log
##[error]Error: Npm failed with return code: 134
##[section]Finishing: npm compile
This error happens when Node.js crashes unexpectedly during compilation. I’ve dealt with Angular builds on Azure DevOps before - the fact that it’s inconsistent between agent types screams resource contention on shared infrastructure. Hosted agents share compute with other builds running at the same time, which is why your pipeline sometimes works and sometimes doesn’t. I’ve had success adding retry logic to the build task to handle these random failures. Try running builds during off-peak hours when there’s less competition for resources. Another trick that worked for me was breaking the build into smaller pieces to reduce memory usage during compilation.
Exit code 134 indicates a memory-related crash during the build process. I faced a similar intermittent issue with Angular builds on Azure DevOps hosted agents some time ago. This is often due to inadequate memory during production builds, as TypeScript compilation and optimization can be resource-intensive. To mitigate this, you can set the NODE_OPTIONS environment variable in your build task to add --max_old_space_size=4096 to your Node.js options. Additionally, consider switching to ubuntu-latest hosted agents, as they typically manage memory more efficiently than Windows agents. Given that your on-premise agent functions well, it’s clear that memory constraints are affecting your builds there. Reducing bundle size by utilizing tree-shaking and eliminating unused dependencies can also help lower memory usage during builds.
I feel your pain! Same thing’s happened to me. Hosted agents are notorious for memory issues. Bump up that memory limit first. If that doesn’t work, go self-hosted - you won’t be fighting other users for resources.