How to see console.log errors in the deploy log on Netlify

I was making an async shortcode in eleventy (static site generator) recently. I needed to see the errors that were logged via console.log() or console.warn() inside the deploy log on Netlify to troubleshoot issues.

The warning thrown from this code did not appear in the deploy log:

Javascript
try {
filepath = nodePath.join(process.cwd(), "src", path);
let data = await ffprobe(filepath);

let { width } = data.streams[0];
let { height } = data.streams[0];

dimensions = { width, height };
} catch (err) {
console.warn(
`getDimensions(): Could not get dimensions for ${filepath}. Err: ${err.message}.`
);
}

In order to see errors and warnings logged, I discovered that you need to have the build command include a CI environment variable. Adding the environment variable to the start of the build command in my netlify.toml was sufficient to enable logging of my warning.

TOML
[build]
command = "CI= pnpm build"
publish = "_site"

This is what you see in the deploy log…

screenshot of deploy log showing errors from the getDimensions() function

Hope it helps! 🧑‍💻💕

Tagged