From e5b0fd7dc6e288f5b994e90eb3e759b2d776060e Mon Sep 17 00:00:00 2001 From: Ricardo Date: Wed, 18 Feb 2026 09:59:00 +0100 Subject: [PATCH] fix: gracefully handle htmlmin parse errors instead of crashing build Malformed HTML (e.g. unescaped quotes in iframe title attributes) caused html-minifier-terser to throw a fatal parse error, killing the entire Eleventy build. Now catches the error, logs a warning, and returns the unminified content so the build completes. --- eleventy.config.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/eleventy.config.js b/eleventy.config.js index 1617781..c0c815c 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -220,14 +220,19 @@ export default function (eleventyConfig) { // HTML minification — only during initial build, skip during watch rebuilds eleventyConfig.addTransform("htmlmin", async function (content, outputPath) { if (outputPath && outputPath.endsWith(".html") && process.env.ELEVENTY_RUN_MODE === "build") { - return await minify(content, { - collapseWhitespace: true, - removeComments: true, - html5: true, - decodeEntities: true, - minifyCSS: false, - minifyJS: false, - }); + try { + return await minify(content, { + collapseWhitespace: true, + removeComments: true, + html5: true, + decodeEntities: true, + minifyCSS: false, + minifyJS: false, + }); + } catch { + console.warn(`[htmlmin] Parse error in ${outputPath}, skipping minification`); + return content; + } } return content; });