Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier fails with Bun workspaces #26265

Open
medz opened this issue Mar 7, 2025 · 4 comments
Open

Prettier fails with Bun workspaces #26265

medz opened this issue Mar 7, 2025 · 4 comments

Comments

@medz
Copy link

medz commented Mar 7, 2025

Summary

Prettier path determination fails in Bun workspace monorepo projects, preventing code formatting.

Steps to trigger the problem:

  1. Open Zed editor with a clean installation.
  2. Open a monorepo project managed by Bun workspace. The project should have a package.json file at the root with a workspaces field defining the workspaces.
  3. Navigate to a package within the monorepo (e.g., packages/your-package-name).
  4. Open a Javascript or Typescript file within this package (e.g., index.js or index.ts).
  5. Attempt to format the file using Prettier (e.g., save the file if format on save is enabled, or use the format command).

Actual Behavior:

Zed displays an error message indicating Prettier path determination failure. The error message is similar to:

[ERROR] Failed to determine prettier path for buffer: Path "[Monorepo Root Path]" is the workspace root for project in "[Package Path]", but it has no prettier installed

The code file is not formatted by Prettier.

Expected Behavior:

The code file within the monorepo package should be automatically formatted by Prettier upon saving or when manually triggered, without any error messages. Prettier should be correctly located and executed within the Bun workspace monorepo environment.

Additional Information:

  • Project Structure: This issue is specific to monorepo projects organized using Bun workspaces. The project root contains a package.json file with a workspaces field defining the workspaces. Each workspace (package) is located in a subdirectory (e.g., packages/*).
  • Runtime: Node.js runtime environment is used for these projects.
  • Bun Workspace Configuration: Bun workspaces are configured within the package.json file using the workspaces field, similar to Yarn or npm workspaces.
  • Prettier Installation: Prettier is likely installed at the root of the monorepo project as a dev dependency. It might not be directly installed within each individual package. This is a common practice in monorepos to centralize dependency management.
  • Configuration Files:
    • package.json: Please see the example package.json configuration below. This file defines the Bun workspaces using the workspaces field.
    • Prettier Configuration: The project might have a Prettier configuration file at the root (e.g., .prettierrc.json, .prettierrc.js, prettier.config.js). Please see an example if relevant.
    • Zed Settings: Are there any specific Zed settings (settings.json) that might be relevant to Prettier integration or path detection in monorepo setups? If so, please provide relevant snippets.
  • Intermittency: This issue appears to be consistent in Bun workspace monorepo projects. It reliably prevents Prettier from formatting code in packages within the monorepo.
  • Workaround: As of now, no known workaround has been found to enable Prettier formatting within Zed in this specific monorepo setup. Manually running Prettier from the command line within the package directory might work, but automatic formatting within Zed is broken.
  • Zed.log: I will check the Zed.log file for any relevant error details and append them to this report if found.

Example package.json with Bun Workspaces Configuration:

See inside for package.json (Workspaces Example)
{
  "name": "monorepo-root",
  "private": true,
  "workspaces": [
    "packages/*",
    "apps/*"
  ]
}
</details>

### Zed Version and System Specs

Zed: v0.176.3 (Zed) 
OS: macOS 15.3.1
Memory: 36 GiB
Architecture: aarch64
@medz
Copy link
Author

medz commented Mar 7, 2025

2025-03-07T13:47:54.359254+08:00 [INFO] Initializing default prettier with plugins {}
2025-03-07T13:47:54.566689+08:00 [ERROR] Failed to determine prettier path for buffer: Path "/Users/seven/workspace/panews-api-server" is the workspace root for project in "/Users/seven/workspace/panews-api-server/packages/binance-announcement", but it has no prettier installed
2025-03-07T13:47:54.691797+08:00 [ERROR] language not found
2025-03-07T13:47:57.762368+08:00 [WARN] Get completion via vtsls failed: Request textDocument/completion failed with message: Reduce of empty array with no initial value
2025-03-07T13:47:57.90425+08:00 [WARN] Get completion via vtsls failed: Request textDocument/completion failed with message: Reduce of empty array with no initial value
2025-03-07T13:47:58.012669+08:00 [WARN] Get completion via vtsls failed: Request textDocument/completion failed with message: Reduce of empty array with no initial value
2025-03-07T13:47:58.181144+08:00 [WARN] Get completion via vtsls failed: Request textDocument/completion failed with message: Reduce of empty array with no initial value
2025-03-07T13:47:58.254217+08:00 [WARN] Get completion via vtsls failed: Request textDocument/completion failed with message: Reduce of empty array with no initial value
2025-03-07T13:47:58.462346+08:00 [WARN] Get completion via vtsls failed: Request textDocument/completion failed with message: Reduce of empty array with no initial value
2025-03-07T13:47:58.629083+08:00 [WARN] Get completion via vtsls failed: Request textDocument/completion failed with message: Reduce of empty array with no initial value
2025-03-07T13:48:00.96234+08:00 [ERROR] Failed to determine prettier path for buffer: Path "/Users/seven/workspace/panews-api-server" is the workspace root for project in "/Users/seven/workspace/panews-api-server/packages/binance-announcement", but it has no prettier installed
2025-03-07T13:48:01.081619+08:00 [ERROR] language not found
2025-03-07T13:48:04.505008+08:00 [INFO] Initializing default prettier with plugins {}
2025-03-07T13:48:04.515551+08:00 [INFO] Initializing default prettier with plugins {}
2025-03-07T13:48:04.530149+08:00 [INFO] Initializing default prettier with plugins {}
2025-03-07T13:48:04.58894+08:00 [INFO] Initializing default prettier with plugins {}
2025-03-07T13:48:06.221874+08:00 [ERROR] Failed to determine prettier path for buffer: Path "/Users/seven/workspace/panews-api-server" is the workspace root for project in "/Users/seven/workspace/panews-api-server/packages/binance-announcement", but it has no prettier installed
2025-03-07T13:48:06.314463+08:00 [ERROR] language not found
2025-03-07T13:48:08.633862+08:00 [ERROR] Failed to determine prettier path for buffer: Path "/Users/seven/workspace/panews-api-server" is the workspace root for project in "/Users/seven/workspace/panews-api-server/packages/binance-announcement", but it has no prettier installed
2025-03-07T13:48:08.64336+08:00 [ERROR] language not found
2025-03-07T13:48:21.273728+08:00 [ERROR] Failed to determine prettier path for buffer: Path "/Users/seven/workspace/panews-api-server" is the workspace root for project in "/Users/seven/workspace/panews-api-server/packages/binance-announcement", but it has no prettier installed
2025-03-07T13:48:21.358656+08:00 [ERROR] language not found
2025-03-07T13:48:24.624045+08:00 [ERROR] Failed to determine prettier path for buffer: Path "/Users/seven/workspace/panews-api-server" is the workspace root for project in "/Users/seven/workspace/panews-api-server/packages/binance-announcement", but it has no prettier installed
2025-03-07T13:48:24.634297+08:00 [ERROR] language not found
2025-03-07T13:48:32.006198+08:00 [ERROR] Failed to determine prettier path for buffer: Path "/Users/seven/workspace/panews-api-server" is the workspace root for project in "/Users/seven/workspace/panews-api-server/packages/binance-announcement", but it has no prettier installed
2025-03-07T13:48:32.131772+08:00 [ERROR] language not found
2025-03-07T13:48:33.106392+08:00 [ERROR] language not found
2025-03-07T13:48:33.265553+08:00 [ERROR] language not found
2025-03-07T13:48:33.539638+08:00 [ERROR] language not found
2025-03-07T13:49:07.245471+08:00 [INFO] Initializing default prettier with plugins {}
2025-03-07T13:49:07.282957+08:00 [ERROR] failed to get git blame data: Failed to blame "node_modules/puppeteer-core/lib/types.d.ts"

Caused by:
    Broken pipe (os error 32)
2025-03-07T13:49:07.308675+08:00 [INFO] Language server with id 11 sent unhandled notification eslint/noLibrary:
{
  "source": {
    "uri": "file:///Users/seven/workspace/panews-api-server/node_modules/puppeteer-core/lib/types.d.ts"
  }
}
2025-03-07T13:49:22.384552+08:00 [INFO] Initializing default prettier with plugins {}
2025-03-07T13:49:28.304547+08:00 [ERROR] language not found
2025-03-07T13:49:28.305047+08:00 [INFO] Initializing default prettier with plugins {}
2025-03-07T13:49:28.608266+08:00 [ERROR] language not found

@osiewicz
Copy link
Contributor

osiewicz commented Mar 7, 2025

Do you have a node_modules folder at the root of your Zed workspace? It looks like we expect ZED_WORKSPACE_ROOT/node_modules/prettier to be a valid path.

let possible_node_modules_location = path.join("node_modules").join(PRETTIER_PACKAGE_NAME);

@osiewicz osiewicz changed the title monorepo Prettier fails with Bun workspaces Mar 7, 2025
@medz
Copy link
Author

medz commented Mar 8, 2025

Do you have a node_modules folder at the root of your Zed workspace? It looks like we expect ZED_WORKSPACE_ROOT/node_modules/prettier to be a valid path.

zed/crates/prettier/src/prettier.rs

Line 511 in d1c6789

let possible_node_modules_location = path.join("node_modules").join(PRETTIER_PACKAGE_NAME);

After using Bun workspace, only root node_modules exists. In addition, I did not install prettier separately. Because Zed has always automatically installed a copy of prettier globally for formatting code. Strangely, it sometimes works, but for example, when I create a new package in packages, it will fail. When I delete everything in the cache and restart Zed, the automatic format will suddenly work again.

@matthewmorek
Copy link

matthewmorek commented Mar 9, 2025

In my case the logs look like this. Prettier stopped working in any apps or packages of my monorepo (using Turborepo). No amount of reconfiguring Prettier, restarting language servers or Zed itself helps in this instance. Monorepo is using pnpm workspaces.

Version: Zed 0.176.3
Build: fbfa89356e8e74041585f721665f3016b0ba498a
2025-03-09T02:17:10.969445Z [INFO] Found prettier in "/Users/mmorek/Projects/playairsoft/playairsoft", starting.
2025-03-09T02:17:10.972378Z [INFO] Starting prettier at path "{project_path}"
2025-03-09T02:17:11.15817Z [INFO] starting language server process.
  binary path: "/usr/local/bin/node",
  working directory: "{project_path}",
  args: ["/Users/mmorek/Library/Application Support/Zed/prettier/prettier_server.js", "{project_path}"]
2025-03-09T02:17:11.205834Z [ERROR] cannot read LSP message headers
2025-03-09T02:17:11.205917Z [ERROR] Broken pipe (os error 32)
2025-03-09T02:17:11.205967Z [ERROR] server shut down
2025-03-09T02:17:11.206009Z [ERROR] Formatting failed: prettier at "{project_path}" failed to spawn: default prettier spawn: prettier server initialization: oneshot canceled
2025-03-09T02:17:11.206054Z [ERROR] prettier at "{project_path}" failed to spawn: default prettier spawn: prettier server initialization: oneshot canceled

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

No branches or pull requests

3 participants