Skip to content

Plugin chaining (sort-imports) silently fails on Windows when loaded via prettier-vscode #455

@llanesluis

Description

@llanesluis

What version of prettier-plugin-tailwindcss are you using?

v0.7.3 (regression — v0.7.2 works correctly on the same setup, also reproduced on 0.0.0-insiders.f7d2598)

What version of Tailwind CSS are you using?

v4.x

What version of Node.js are you using?

v24.11.0

What package manager are you using?

pnpm v10.28.2

What operating system are you using?

Windows 11

Reproduction URL

https://github.com/llanesluis/plugin-chaining-fails-silently

NOTE: The repo includes a REPRODUCTION_STEPS.md file for guidance.

Describe your issue

When prettier-plugin-tailwindcss@0.7.3 is combined with @ianvs/prettier-plugin-sort-imports and Prettier is invoked through the prettier-vscode VS Code extension on Windows (format on save), the sort-imports chain silently fails — imports are never reordered on save. Tailwind class sorting and base Prettier formatting still work on the same save.

Running Prettier from the CLI (prettier --write) on the same project and config works correctly: imports are reordered and grouped as expected, Tailwind class sorting and base Prettier formatting work too.

This is a regression from v0.7.2 → v0.7.3. Pinning prettier-plugin-tailwindcss@0.7.2 makes the problem disappear entirely; upgrading to 0.7.3 reintroduces it.


Identified potential root cause

In dist/index.mjs, findEnabledPlugin does:

if (typeof plugin !== "string") { plugin = plugin.name; }
if (plugin === name || isAbsolute(plugin) && plugin.includes(name) && maybeResolve(name) === plugin)
  return loadIfExists(name);

Prettier CLI sets plugin.name to the package name "@ianvs/prettier-plugin-sort-imports" → plugin === name matches → chain succeeds.
prettier-vscode resolves package names to file paths before Prettier loads them, so plugin.name ends up as the native Windows path, e.g.:

D:\…\node_modules\…\@ianvs\prettier-plugin-sort-imports\lib\src\index.js

On Windows the package segment is "@ianvs\prettier-plugin-sort-imports" (backslash), but name is "@ianvs/prettier-plugin-sort-imports" (forward slash). → plugin.includes(name) returns false → chain drops silently.

Verified local patch

Applied via pnpm patch against prettier-plugin-tailwindcss@0.7.3 — after this patch, VS Code save and CLI both correctly chain the sort-imports plugin:

--- a/dist/index.mjs
+++ b/dist/index.mjs
@@ -386,7 +386,9 @@ function findEnabledPlugin(options, name) {
 			if (!plugin.name) continue;
 			plugin = plugin.name;
 		}
-		if (plugin === name || isAbsolute(plugin) && plugin.includes(name) && maybeResolve(name) === plugin) return loadIfExists(name);
+		const pluginSlashed = plugin.replace(/\\/g, "/");
+		const resolvedSlashed = maybeResolve(name)?.replace(/\\/g, "/") ?? null;
+		if (plugin === name || (isAbsolute(plugin) && pluginSlashed.includes(name) && resolvedSlashed === pluginSlashed)) return loadIfExists(name);
 	}
 }

Tested on Windows 11 with both npm and pnpm across plain Next.js (minimal reproduction uses Next.js app) and a pnpm monorepo — both CLI and prettier-vscode save work after the patch, on paths with and without spaces.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions