biomejs / biome-vscode

Biome extension for Visual Studio Code and VSCodium
https://marketplace.visualstudio.com/items?itemName=biomejs.biome
Apache License 2.0
237 stars 32 forks source link

πŸ› Error when running format: Extension 'Biome' is configured as formatter but it cannot format 'TypeScript JSX'-files #302

Closed graup closed 3 months ago

graup commented 3 months ago

VS Code version

1.92.1

Extension version

v2024.5.251958

Biome version

1.8.3

Operating system

Description

I installed the Biome extension according to the docs as well as Biome itself (yarn add -D @biomejs/biome). I tried this both with the latest stable and pre-release extension version. The CLI works fine but I cannot get the extension to work.

My VSCode settings:

  "[javascript][javascriptreact][typescript][typescriptreact][json][jsonc]": {
    "editor.defaultFormatter": "biomejs.biome"
  },
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
      "quickfix.biome": "explicit",
      "source.organizeImports.biome": "explicit"
  },

Now when I open a TSX file, I don't get any squiggly lines. Also, when I manually run "Format Document", I get this error: "Extension 'Biome' is configured as formatter but it cannot format 'TypeScript JSX'-files"

Screenshot 2024-08-14 at 10 39 04

Furthermore, every time I open the workspace, it complains that the Biome CLI is not installed even though it is. (I open the root of my repo which has the biome.json and package.json, biome was installed in node_modules with yarn 3.6.3.)

Maybe related to https://github.com/biomejs/biome-vscode/issues/283

Steps to reproduce

Install Biome and extension according to docs.

Open your project root folder in VSCode.

Open a TSX file.

Linting and formatting does not work.

Expected behavior

Works.

Does this issue occur when using the CLI directly?

No

Logs

No response

ematipico commented 3 months ago

Do you use yarn pnp? Which version of yarn do you use? Have you tried another package manager?

Ultimately, can you provide a reproduction?

graup commented 3 months ago

I'm using yarn with node_modules

yarnPath: .yarn/releases/yarn-3.6.3.cjs
nodeLinker: node-modules

Is your guess that the root cause of the error is that the extension cannot find the CLI?

I'll try to create an isolated reproduction.

ematipico commented 3 months ago

It's possible that yarn didn't install the optional dependencies.

You should see a @biomejs/cli-* inside your node modules folder

graup commented 3 months ago

Here's a minimal repo: https://github.com/graup/biome-test

This is what node_modules looks like:

Screenshot 2024-08-14 at 11 13 47

Jayllyz commented 3 months ago

It worked for me using your repro.

clone -> yarn install -> reload VS code (you need to reload Vs code if you install Biome after extension init)

ematipico commented 3 months ago

It worked for me using your repro.

clone -> yarn install -> reload VS code (you need to reload Vs code if you install Biome after extension init)

We should probably add this important detail in our documentation

graup commented 3 months ago

That's weird. I already tried restarting or reloading VSCode, this doesn't fix the problem for me. Maybe something off with my VSCode... I just tried resetting my VSCode settings and disabled all other extensions but I'm still getting the same error "Could not find Biome in your dependencies."

(To clarify, I'm opening the root folder in VSCode.)

Tylermeek commented 3 months ago

my way to solve this problem: check node_modules, find out there is no @biomejs -> del node_modules and pnpm-lock.yaml -> pnpm i -> reload vscode after that, it finally work

krishna-gujjjar commented 3 months ago

Same here with yarn.

When yarn building process not successfully done or yarn checksum issue, then the vscode not found biome as formatter. Just switch with bun or pnpm and re-install the deps.

graup commented 3 months ago

I'm afraid using a different package manager is not an option for me, this is a large project in production.

Could nobody else reproduce my issue in my repro?

nhedger commented 3 months ago

What does the Biome output say ?

graup commented 3 months ago

The CLI works as expected.

 yarn lint
test.tsx:2:3 lint/style/useConst  FIXABLE  ━━━━━━━━━━━━━

  βœ– This let declares a variable that is only assigned once.

    1 β”‚ function foo() {
  > 2 β”‚   let v = 1;
      β”‚   ^^^
    3 β”‚   return <div>{v}</div>;
    4 β”‚ }

  β„Ή 'v' is never reassigned.

    1 β”‚ function foo() {
  > 2 β”‚   let v = 1;
      β”‚       ^
    3 β”‚   return <div>{v}</div>;
    4 β”‚ }

  β„Ή Safe fix: Use const instead.

    1 1 β”‚   function foo() {
    2   β”‚ - Β·Β·letΒ·vΒ·=Β·1;
      2 β”‚ + Β·Β·constΒ·vΒ·=Β·1;
    3 3 β”‚     return <div>{v}</div>;
    4 4 β”‚   }

Checked 2 files in 40ms. No fixes applied.
Found 1 error.
check ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  βœ– Some errors were emitted while running checks.
nhedger commented 3 months ago

Sorry I meant the Biome output in VS Code. In your output panel you should see Biome and there should be the logs of the extension. Hopefully it tells us more about why the session is not being created

graup commented 3 months ago

Biome output in VSCode:

Could not resolve Biome in the dependencies of workspace folder: /path/to/biome-test
Searching for Biome in PATH
Extension bundle does not include the prebuilt binary

And the "Biome Trace" output is empty.

nhedger commented 3 months ago

It looks like your biome.lspBin setting is set.

In this case, the extension will attempt to resolve Biome from the path /path/to/biome-test, bypassing the resolution of Biome from node_modules.

Try deleting the biome.lspBin setting from your settings.json file.

Actually, I was wrong. The error is triggered when the actual bin file cannot be found on disk.

graup commented 3 months ago

Thanks for the idea. However, I have not set biome.lspBin in either my user settings nor the workspace settings. So it's the default value, "biome.lspBin": "".

nhedger commented 3 months ago

Using you repro, it finds the binary correctly.

Biome binary found at /Users/nicolas/code/repro/biome-test/node_modules/@biomejs/cli-darwin-x64/biome

Also, you mentioned using Yarn 3.6.3 but your repo has Yarn 4.4.0.

graup commented 3 months ago

Yeah, I tried updating yarn, but it didn't help.

Hmm, so it must be something with my environment. I will keep trouble-shooting and report back if I find anything.

Thanks for your help so far.

nhedger commented 3 months ago

Would you mind trying to install with npm instead just to see if this has an impact ?

graup commented 2 days ago

I finally managed to test it with a different package manager. Happy to report that it works fine in pnpm. So maybe a yarn issue in my specific environment