nx
nx copied to clipboard
format:write fails with Prettier 4 due to write/list-different combo
Description
Upgrading a workspace to Prettier 4.0.0-alpha.13 causes npx nx format:write (including --uncommitted) to fail. Nx invokes Prettier with both --write and --list-different, but Prettier 4 now treats that combination as invalid and exits with an error.
The error from Prettier is:
Incompatible options: "write" and "list-different" cannot be used together
As a result, nx format:write can no longer run when Prettier 4 is installed.
Reproduction
# install Prettier 4 alpha
bun add [email protected]
# or: npm install --save-dev [email protected]
# run Nx formatting on uncommitted changes
npx nx format:write --uncommitted
Expected behavior
Nx should still be able to format files when a project upgrades to Prettier 4. It should not pass incompatible flags to Prettier.
Actual behavior
Prettier exits with status 1 and prints:
Incompatible options: "write" and "list-different" cannot be used together
Nx surfaces this as a failed format:write command.
Environment
- Nx 22.1.1
- Prettier 4.0.0-alpha.13
- Works fine with Prettier 3.4.x in the same workspace
Suggested fix
When invoking Prettier in write mode, do not also pass --list-different (or otherwise adjust the integration so that Prettier 4 is not called with incompatible option combinations).