Bryan Primus

Force use of bun

1 min read | Written on 2025-07-04

While I’m scaffolding a new project and configuring Prettier using bun, I realized that when I run prettier --write against the prettier.config.ts file, I get this error:

[error] Invalid configuration for file "[PROJECT-PATH]/.gitignore": 
[error] Unknown file extension ".ts" for [PROJECT-PATH]/prettier.config.ts

This shouldn’t happen since I’m using bun, and it has TypeScript support by default.
Turns out, when running Prettier (which I’ve configured in my package.json scripts like this):

"scripts": {
  "format": "prettier --write ."
}

Even though I ran the command using bun format in the terminal, it still uses node to run the CLI.
It doesn’t really make sense, since the default runtime should be bun.

To fix this, I found that I can force bun to be used like this:

bun --bun prettier --write .

Not convenient, considering I might forget to add that flag.

So for now, I just hardcoded the command in package.json:

"scripts": {
  "format": "bun --bun prettier --write ."
}

Now I can run bun format without error, or even use another package manager like npm run format or yarn format, and it’ll still work and still using bun under the hood.

Daily News

I like to read only 3 news every day