Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bun in VS Code: error "Cannot find name Bun" when using the Bun singleton

The problem I'm experiencing

I installed Bun in WSL and connected to it via VS Code, but when I tried to use Bun.serve in my code, VS Code shows an error saying Cannot find name 'Bun'. I know this is because VS Code doesn't know that I'm using Bun, but I don't know how I can make VS Code recognize Bun.

What I tried

I tried installing the official Bun VS Code extension, but the error persisted. I also searched on Google but I didn't find anything.

What I was expecting

The error should stop showing and ideally VS Code should provide autocompletion for the Bun singleton.

like image 269
terraquad Avatar asked May 19 '26 15:05

terraquad


2 Answers

have you try this one:

On TS you need to install bun-types as devDependency.

Command:

bun add -d bun-types

tsconfig.json file:

{
        "compilerOptions": {
            "types": [
                "bun-types"
            ]
        }
}

Follow this doc: https://bun.sh/docs/runtime/typescript

like image 126
yushaku Avatar answered May 21 '26 15:05

yushaku


For those who are still encountering this issue, here is the updated fix

  1. Install the @types/bun as the dev dependency
bun add -d @types/bun
  1. Update tsconfig.json compilerOptions > types (add if missing)
{
  "compilerOptions": {
     "types": ["bun"],
//..
like image 36
Ron Michael Avatar answered May 21 '26 15:05

Ron Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!