`KeyError: 'writer'` with myST-Parser since PR #13676
Describe the bug
make html fails with error KeyError: 'writer' in presence of myST-Parser and meta data at start of index.md.
How to Reproduce
Use this file index.md:
---
myst:
html_meta:
keywords: Bug
---
# FOO documentation
and make sure conf.py contains:
extensions = [
'myst_parser',
]
source_suffix = {
'.rst': 'restructuredtext',
'.md': 'markdown',
}
Environment Information
$ make clean html
Removing everything under '_build'...
Running Sphinx v8.3.0+/114093cff
Sphinx version: 8.3.0+/114093cff
Python version: 3.13.3 (CPython)
Docutils version: 0.21.2
Pygments version: 2.19.1
Jinja2 version: 3.1.6
loading translations [en]... done
making output directory... done
myst v4.0.1: MdParserConfig(commonmark_only=False, gfm_only=False, enable_extensions=set(), disable_syntax=[], all_links_external=False, links_external_new_tab=False, url_schemes=('http', 'https', 'mailto', 'ftp'), ref_domains=None, fence_as_directive=set(), number_code_blocks=[], title_to_header=False, heading_anchors=0, heading_slug_func=None, html_meta={}, footnote_sort=True, footnote_transition=True, words_per_minute=200, substitutions={}, linkify_fuzzy_links=True, dmath_allow_labels=True, dmath_allow_space=True, dmath_allow_digits=True, dmath_double_inline=False, update_mathjax=True, mathjax_classes='tex2jax_process|mathjax_process|math|output_area', enable_checkboxes=False, suppress_warnings=[], highlight_code_blocks=True)
building [mo]: targets for 0 po files that are out of date
writing output...
building [html]: targets for 1 source files that are out of date
updating environment: [new config] 1 added, 0 changed, 0 removed
reading sources... [100%] index
Versions
========
* Platform: darwin; macOS 15.5 arm64
* Python version: 3.13.3 (CPython)
* Sphinx version: 8.3.0+/114093cff
* Docutils version: 0.21.2
* Jinja2 version: 3.1.6
* Pygments version: 2.19.1
Last Messages
=============
writing output...
building [html]: targets for 1 source files that are out of date
updating environment:
[new config]
1 added, 0 changed, 0 removed
reading sources... [100%]
index
Loaded Extensions
=================
* sphinx.ext.mathjax (8.3.0+/114093cff)
* alabaster (1.0.0)
* sphinxcontrib.applehelp (2.0.0)
* sphinxcontrib.devhelp (2.0.0)
* sphinxcontrib.htmlhelp (2.1.0)
* sphinxcontrib.serializinghtml (2.0.0)
* sphinxcontrib.qthelp (2.0.0)
* myst_parser (4.0.1)
Traceback
=========
File "/path/to/.venv313/lib/python3.13/site-packages/docutils/transforms/components.py", line 48, in apply
component = self.document.transformer.components[component_type]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: 'writer'
Sphinx extensions
``myST-Parser 4.0.1``
Additional context
git bisect blames 114093cff01562a6a50f8c88b59c7b2fed52a39a (#13676)
Perhaps related to @bsipocz's comments in https://github.com/sphinx-doc/sphinx/pull/13644#issuecomment-3029959864.
A
@jfbu can you paste the full traceback (--show-traceback)?
A
@AA-Turner here it is:
Versions
========
* Platform: darwin; (macOS-15.7.2-arm64-arm-64bit-Mach-O)
* Python version: 3.13.3 (CPython)
* Sphinx version: 9.0.0rc1+/113cfe161
* Docutils version: 0.22.3
* Jinja2 version: 3.1.6
* Pygments version: 2.19.1
Last Messages
=============
writing output...
building [html]: targets for 1 source files that are out of date
updating environment:
[new config]
1 added, 0 changed, 0 removed
reading sources... [100%]
index
Loaded Extensions
=================
* sphinx.ext.mathjax (9.0.0rc1+/113cfe161)
* alabaster (1.0.0)
* sphinxcontrib.applehelp (2.0.0)
* sphinxcontrib.devhelp (2.0.0)
* sphinxcontrib.htmlhelp (2.1.0)
* sphinxcontrib.serializinghtml (2.0.0)
* sphinxcontrib.qthelp (2.0.0)
* myst_parser (4.0.1)
Traceback
=========
Traceback (most recent call last):
File "/Path/To/sphinx/sphinx/cmd/build.py", line 432, in build_main
app.build(args.force_all, args.filenames)
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Path/To/sphinx/sphinx/application.py", line 440, in build
self.builder.build_update()
~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/Path/To/sphinx/sphinx/builders/__init__.py", line 380, in build_update
self.build(
~~~~~~~~~~^
to_build,
^^^^^^^^^
...<2 lines>...
method='update',
^^^^^^^^^^^^^^^^
)
^
File "/Path/To/sphinx/sphinx/builders/__init__.py", line 408, in build
updated_docnames = set(self.read())
~~~~~~~~~^^
File "/Path/To/sphinx/sphinx/builders/__init__.py", line 524, in read
self._read_serial(docnames)
~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "/Path/To/sphinx/sphinx/builders/__init__.py", line 589, in _read_serial
self.read_doc(docname)
~~~~~~~~~~~~~^^^^^^^^^
File "/Path/To/sphinx/sphinx/builders/__init__.py", line 652, in read_doc
doctree = _parse_str_to_doctree(
content,
...<6 lines>...
transforms=self._registry.get_transforms(),
)
File "/Path/To/sphinx/sphinx/util/docutils.py", line 894, in _parse_str_to_doctree
transformer.apply_transforms()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/Path/To/sphinx/sphinx/transforms/__init__.py", line 95, in apply_transforms
super().apply_transforms() # type: ignore[misc]
~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/Path/To/VENV313/lib/python3.13/site-packages/docutils/transforms/__init__.py", line 193, in apply_transforms
transform.apply(**kwargs)
~~~~~~~~~~~~~~~^^^^^^^^^^
File "/Path/To/VENV313/lib/python3.13/site-packages/docutils/transforms/components.py", line 50, in apply
component = self.document.transformer.components[component_type]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: 'writer'
See https://github.com/executablebooks/MyST-Parser/pull/1076#issuecomment-3656014521
Closing in favour of the linked issue.
A