2025, Oct 21 01:00
Pelican build fails on minify(): how to fix unexpected keyword argument TypeError after minify-html update
Pelican crashing on minify() with TypeError after a dependency update? Fix it by updating the minify plugin to new minify-html parameters and restore builds.
Pelican may suddenly fail during site generation after updating dependencies, even when nothing in your content changed. A common example is a crash on the minification step with a TypeError that points to unexpected keyword arguments. If your build stops on an HTML like output/archives.html and the stack ends with a message about minify(), you are likely hitting a recent breaking change in minify-html.
CRITICAL Exception: Unable to minify file output\archives.html. Exception was: TypeError("minify() got an unexpected keyword argument 'do_not_minify_doctype'")
Reproducing the failing call
In this scenario the issue lives in the Pelican minify plugin. The call into minify-html uses argument names that no longer exist after the breaking change. The logic is straightforward: pass the HTML through minify_html.minify with CSS and JS minification flags and preserve the doctype and attribute spacing. The problematic version looks like this:
def compress_markup(self, html_blob, shrink_css, shrink_js):
    return minify_html.minify(
        html_blob,
        do_not_minify_doctype=True,
        keep_spaces_between_attributes=True,
        minify_css=shrink_css,
        minify_js=shrink_js,
    )
What’s actually going wrong
The minify-html library introduced a breaking change (see 0.16.0 notes). The keyword arguments do_not_minify_doctype and keep_spaces_between_attributes were removed and replaced. As a result, older callers pass names the function no longer accepts, and Python raises a TypeError for unexpected keyword arguments. The Pelican plugin still uses the old names, so the failure surfaces in Pelican even though the root cause is the API change in minify-html.
If you search for the text Unable to minify file in your project, you will discover the call chain in Pelican rather than in minify-html itself. The relevant code path is in pelican\plugins\minify\minify.py.
The fix
Update the call site to use the new parameter names and equivalent semantics. The goal remains the same: preserve the doctype and keep spaces between attributes while optionally minifying CSS and JS. The corrected call maps to the new parameters minify_doctype and allow_removing_spaces_between_attributes with inverted Boolean values to achieve the same behavior.
def compress_markup(self, html_blob, shrink_css, shrink_js):
    return minify_html.minify(
        html_blob,
        minify_doctype=False,
        allow_removing_spaces_between_attributes=False,
        minify_css=shrink_css,
        minify_js=shrink_js,
    )
Why this matters
Static site builds should be deterministic. When transitive dependencies introduce breaking changes, failures appear in places that look unrelated to the change, which complicates debugging. Recognizing that the error text mentions unexpected keyword argument and knowing where the minify call originates helps you resolve the issue quickly without resorting to downgrades.
It’s also a reminder to inspect the caller first. Searching for Unable to minify file within Pelican leads directly to the minify plugin, where you can align the argument names with the current minify-html API.
Takeaways
If Pelican exits with a TypeError on minify() after a dependency update, check pelican\plugins\minify\minify.py for outdated argument names. Replace do_not_minify_doctype with minify_doctype=False and keep_spaces_between_attributes with allow_removing_spaces_between_attributes=False, keeping the CSS and JS flags as they are. This keeps the original behavior intact and restores a clean build without pinning older packages.