Skip to content

Fix "Missing visitor keys for 'undefined'" error with multiple Prettier copies - #470

Open
Mohith26 wants to merge 2 commits into
tailwindlabs:mainfrom
Mohith26:fix/missing-visitor-keys-undefined
Open

Fix "Missing visitor keys for 'undefined'" error with multiple Prettier copies#470
Mohith26 wants to merge 2 commits into
tailwindlabs:mainfrom
Mohith26:fix/missing-visitor-keys-undefined

Conversation

@Mohith26

Copy link
Copy Markdown

Fixes #469, reported by @leonwissenberg, with the key reproduction detail from @ChrisMBarr's report in prettier/eslint-plugin-prettier#771.

The plugin wraps parsers it loads from prettier/plugins/html resolved from its own dependency tree, but exported no printer, so the AST was printed by the running Prettier's builtin HTML printer. Prettier 3.7 renamed the HTML AST discriminator from type to kind, so any node_modules tree containing two Prettier copies straddling that boundary makes the printer see undefined node types and throw "Missing visitor keys for 'undefined'". That is why the error appeared after a 3.6 -> 3.7 upgrade and vanished on fresh installs.

The fix adds the html printer to the plugin's exports (mirroring the existing svelte-ast pattern), so parser and printer always come from the same prettier/plugins/html module instance regardless of which Prettier copy the plugin resolves.

CHANGELOG entry added under Unreleased. A new fixture test reproduces the real-world mismatch (repo CLI Prettier vs a fixture-local prettier@3.6.2) and fails with the exact reported error without the fix. Suite: 112 passed, zero new failures; knip/oxlint clean.

Mohith26 added 2 commits July 28, 2026 20:51
…er copies

The plugin resolves `prettier/plugins/html` from its own dependency tree
to obtain the parsers it wraps, but it did not export a matching printer,
so the AST was printed by the running Prettier's builtin HTML printer.
When a dependency tree contains more than one copy of Prettier straddling
the v3.7 boundary (where the HTML AST discriminator was renamed from
`type` to `kind`), the printer receives nodes whose discriminator it
cannot read and throws "Missing visitor keys for 'undefined'".

Export the HTML printer from the same `prettier/plugins/html` module the
parsers are loaded from - mirroring the existing `svelte-ast` printer
export - so the parser and printer always agree on the AST shape.

Fixes tailwindlabs#469
…dlabs#469)

Adds a fixture with its own `prettier@3.6.2` install. The test copies the
built plugin next to it so the plugin resolves the fixture's Prettier copy
while the repo's Prettier CLI formats the file, reproducing the mismatched
setup from the issue. Without the fix this fails with "Missing visitor
keys for 'undefined'".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prettier Error: Missing visitor keys for 'undefined'

1 participant