Hi, @jokuja. The build system VM is destroyed after the build is complete to that file isn’t recoverable. There are several ways to approach working around this.
Also, in most cases, you won’t need to use the detailed logs to debug the issue. If you do, it is likely easier to reproduce the issue locally and debug the issue that way. On the local system, you will be able to easily see those logs.
In other words, this file probably isn’t needed to debug some issue at Netlify. If you do need to use those logs to debug your site build, debugging locally first would likely be best.
However, if you do want to print those logs at Netlify, one method is to print that file to the console to have it logged on build failure only. Depending on how long the file is, you may need to use sleep
to allow all the printed lines to be captured by the logger before the VM is shutdown.
For example, if your build command is this:
npm run build
Then you might log that file and delay exiting like so:
npm run build || { cat /opt/buildhome/.npm/_logs/* ; sleep 30 ; false; }
The “||
” is the logical-OR. It means the code in the brackets will only be run if the original build command exits with an error code.
On other words, the addition above say “only on a build failure, run these commands (below)”:
cat /opt/buildhome/.npm/_logs/*
sleep 30
false
The cat
line prints the logs. The sleep
line delays the exit of the build image to allow the logs to be sent to the logging service. Note, this 30 second sleep might not be long enough if the log file is thousands of lines long. You may need to increase it depending on the file size. The false
exits the build as an error.
Note, the “false;
” at the end code in the brackets above is also quite important (and the ending semi-colon is required as well).
This command being run last means that the exit code will be non-zero. Non-zero exit codes are what determines if a build is a failing build or not. The “false;
” fails the build.
We know this build failed or the code in the brackets would not have been run (because of the “||
”. If the bracket code is run, the false;
will mean the build will still exit as an error. We want the error because we do NOT want to publish a failing build. This is why “false;
” is so important. It make certain the error stays an error. If the build is successful, the bracket code isn’t run so your successful builds won’t print that log or exit “false” - only failing builds will do this.
To summarize, you probably don’t want to print this file at Netlify at all. If you decide to do so anyway, the solution above (or some variation of it) will work.
If there are questions about any of this, please let us know.