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

1.1k views Asked by At

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.

1

There are 1 answers

1
yushaku On BEST ANSWER

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