RuntimePackage ManagerBundlerTest RunnerLinterFormatterGuidesReferenceBlogFeedback

Detect when code is executed with Bun

Check process.versions.bun to detect whether code is running in Bun. This works in both JavaScript and TypeScript without extra type definitions.

TypeScript
if (process.versions.bun) {
  // this code will only run when the file is run with Bun
}

Alternatively, check for the Bun global, the same way you'd check for window to detect a browser.

TypeScript
if (typeof Bun !== "undefined") {
  // this code will only run when the file is run with Bun
}