Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
/dist
plugin-dist
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
### Fixed

- Fix "Missing visitor keys for 'undefined'" error when multiple copies of Prettier exist in a dependency tree ([#469](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/issues/469))

## [0.8.1] - 2026-07-15

Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,15 @@ let html = defineTransform<HtmlNode>({
vue: { dynamicAttrs: [':class', 'v-bind:class'] },
},

// Use the printer from the same `prettier/plugins/html` module the parsers
// come from. When multiple copies of Prettier exist in a dependency tree the
// AST produced by our copy may not match what the running Prettier's builtin
// printer expects (e.g. Prettier v3.7 renamed the HTML AST `type` field to
// `kind`) causing a "Missing visitor keys for 'undefined'" error.
printers: {
html: {},
},

transform: transformHtml,
})

Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,24 @@ describe('fixtures', () => {
expect(formatted.trim()).toEqual(expected.trim())
})
}

// https://github.com/tailwindlabs/prettier-plugin-tailwindcss/issues/469
test.concurrent('multiple copies of Prettier in a dependency tree', async ({ expect }) => {
let fixturePath = path.resolve(__dirname, 'fixtures/prettier-mismatch')
let pluginCopyPath = path.resolve(fixturePath, 'plugin-dist')

// Copy the built plugin into the fixture so it resolves the fixture's
// copy of Prettier while the CLI runs the repo's copy
await fs.cp(path.resolve(__dirname, '../dist'), pluginCopyPath, { recursive: true })

let inputPath = path.resolve(fixturePath, 'index.html')
let outputPath = path.resolve(fixturePath, 'output.html')
let cmd = `${binPath} ${inputPath} --plugin ${pluginCopyPath}/index.mjs`

let results = await execAsync(cmd)
let formatted = results.stdout.replace(/\r\n/g, '\n')
let expected = await fs.readFile(outputPath, 'utf-8').then((c) => c.replace(/\r\n/g, '\n'))

expect(formatted.trim()).toEqual(expected.trim())
})
})
1 change: 1 addition & 0 deletions tests/fixtures/prettier-mismatch/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="sm:p-0 p-0"></div>
1 change: 1 addition & 0 deletions tests/fixtures/prettier-mismatch/output.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="p-0 sm:p-0"></div>
27 changes: 27 additions & 0 deletions tests/fixtures/prettier-mismatch/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/fixtures/prettier-mismatch/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"prettier": "3.6.2"
}
}