每一天,Bun 都更接近 100% Node.js API 兼容性。如今,像 Next.js、Express 等流行框架,以及數百萬個為 Node 設計的 npm 包都能在 Bun 上正常工作。為了確保兼容性,我們在每次發布 Bun 之前都會運行 Node.js 測試套件中的數千個測試。
如果一個包在 Node.js 中有效但在 Bun 中無效,我們認為這是 Bun 的一個 bug。 請 提交問題,我們會修復它。
此頁面會定期更新以反映最新版本 Bun 的兼容性狀態。下面的信息反映了 Bun 與 Node.js v23 的兼容性。
內置 Node.js 模塊
node:assert
🟢 完全實現。
node:buffer
🟢 完全實現。
node:console
🟢 完全實現。
node:dgram
🟢 完全實現。> 90% 的 Node.js 測試套件通過。
node:diagnostics_channel
🟢 完全實現。
node:dns
🟢 完全實現。> 90% 的 Node.js 測試套件通過。
node:events
🟢 完全實現。100% 的 Node.js 測試套件通過。EventEmitterAsyncResource 在底層使用 AsyncResource。
node:fs
🟢 完全實現。92% 的 Node.js 測試套件通過。
node:http
🟢 完全實現。傳出客戶端請求體當前被緩沖而不是流式傳輸。
node:https
🟢 API 已實現,但 Agent 尚未始終使用。
node:os
🟢 完全實現。100% 的 Node.js 測試套件通過。
node:path
🟢 完全實現。100% 的 Node.js 測試套件通過。
node:punycode
🟢 完全實現。100% 的 Node.js 測試套件通過,已被 Node.js 棄用。
node:querystring
🟢 完全實現。100% 的 Node.js 測試套件通過。
node:readline
🟢 完全實現。
node:stream
🟢 完全實現。
node:string_decoder
🟢 完全實現。100% 的 Node.js 測試套件通過。
node:timers
🟢 建議改用全局 setTimeout 等。
node:tty
🟢 完全實現。
node:url
🟢 完全實現。
node:zlib
🟢 完全實現。98% 的 Node.js 測試套件通過。
node:async_hooks
🟡 AsyncLocalStorage 和 AsyncResource 已實現。v8 promise hooks 未被調用,其使用被 強烈不推薦。
node:child_process
🟡 缺少 proc.gid proc.uid。Stream 類未導出。IPC 無法發送 socket 句柄。Node.js ↔ Bun IPC 可以與 JSON 序列化一起使用。
node:cluster
🟡 句柄和文件描述符無法在工作線程之間傳遞,這意味著跨進程的 HTTP 請求負載均衡目前僅在 Linux 上受支持(通過 SO_REUSEPORT)。否則,已實現但未經過實戰測試。
node:crypto
🟡 缺少 secureHeapUsed setEngine setFips
node:domain
🟡 缺少 Domain active
node:http2
🟡 客戶端和服務器已實現(95.25% 的 gRPC 測試套件通過)。缺少 options.allowHTTP1、options.enableConnectProtocol、ALTSVC 擴展和 http2stream.pushStream。
node:module
🟡 缺少 syncBuiltinESMExports、Module#load()。覆蓋 require.cache 對 ESM 和 CJS 模塊受支持。module._extensions、module._pathCache、module._cache 是無操作。module.register 未實現,我們建議暫時使用 Bun.plugin。
node:net
🟢 完全實現。
node:perf_hooks
🟡 API 已實現,但 Node.js 測試套件尚未通過此模塊。
node:process
🟡 請參閱 process 全局對象。
node:sys
🟡 請參閱 node:util。
node:tls
🟡 缺少 tls.createSecurePair。
node:util
🟡 缺少 getCallSite getCallSites getSystemErrorMap getSystemErrorMessage transferableAbortSignal transferableAbortController
node:v8
🟡 writeHeapSnapshot 和 getHeapSnapshot 已實現。serialize 和 deserialize 使用 JavaScriptCore 的線格式而不是 V8 的。其他方法未實現。對於性能分析,請改用 bun:jsc。
node:vm
🟡 核心功能和 ES 模塊已實現,包括 vm.Script、vm.createContext、vm.runInContext、vm.runInNewContext、vm.runInThisContext、vm.compileFunction、vm.isContext、vm.Module、vm.SourceTextModule、vm.SyntheticModule 和 importModuleDynamically 支持。像 timeout 和 breakOnSigint 這樣的選項完全受支持。缺少 vm.measureMemory 和一些 cachedData 功能。
node:wasi
🟡 部分實現。
node:worker_threads
🟡 Worker 不支持以下選項:stdin stdout stderr trackedUnmanagedFds resourceLimits。缺少 markAsUntransferable moveMessagePortToContext。
node:inspector
🔴 未實現。
node:repl
🔴 未實現。
node:sqlite
🔴 未實現。
node:test
🟡 部分實現。缺少 mocks、snapshots、timers。請改用 bun:test。
node:trace_events
🔴 未實現。
Node.js 全局對象
下表列出了 Node.js 實現的所有全局對象以及 Bun 當前的兼容性狀態。
AbortController
🟢 完全實現。
AbortSignal
🟢 完全實現。
Blob
🟢 完全實現。
Buffer
🟢 完全實現。
ByteLengthQueuingStrategy
🟢 完全實現。
__dirname
🟢 完全實現。
__filename
🟢 完全實現。
atob()
🟢 完全實現。
Atomics
🟢 完全實現。
BroadcastChannel
🟢 完全實現。
btoa()
🟢 完全實現。
clearImmediate()
🟢 完全實現。
clearInterval()
🟢 完全實現。
clearTimeout()
🟢 完全實現。
CompressionStream
🟢 完全實現。
console
🟢 完全實現。
CountQueuingStrategy
🟢 完全實現。
Crypto
🟢 完全實現。
SubtleCrypto (crypto)
🟢 完全實現。
CryptoKey
🟢 完全實現。
CustomEvent
🟢 完全實現。
DecompressionStream
🟢 完全實現。
Event
🟢 完全實現。
EventTarget
🟢 完全實現。
exports
🟢 完全實現。
fetch
🟢 完全實現。
FormData
🟢 完全實現。
global
🟢 已實現。這是一個包含全局命名空間中所有對象的對象。它很少被直接引用,因為其內容無需額外前綴即可使用,例如 __dirname 而不是 global.__dirname。
globalThis
🟢 別名為 global。
Headers
🟢 完全實現。
MessageChannel
🟢 完全實現。
MessageEvent
🟢 完全實現。
MessagePort
🟢 完全實現。
module
🟢 完全實現。
PerformanceEntry
🟢 完全實現。
PerformanceMark
🟢 完全實現。
PerformanceMeasure
🟢 完全實現。
PerformanceObserver
🟢 完全實現。
PerformanceObserverEntryList
🟢 完全實現。
PerformanceResourceTiming
🟢 完全實現。
performance
🟢 完全實現。
process
🟡 大部分已實現。process.binding(一些包依賴的內部 Node.js 綁定)部分實現。process.title 目前在 macOS 和 Linux 上是無操作。getActiveResourcesInfo setActiveResourcesInfo、getActiveResources 和 setSourceMapsEnabled 是存根。較新的 API 如 process.loadEnvFile 和 process.getBuiltinModule 尚未實現。
queueMicrotask()
🟢 完全實現。
ReadableByteStreamController
🟢 完全實現。
ReadableStream
🟢 完全實現。
ReadableStreamBYOBReader
🟢 完全實現。
ReadableStreamBYOBRequest
🟢 完全實現。
ReadableStreamDefaultController
🟢 完全實現。
ReadableStreamDefaultReader
🟢 完全實現。
require()
🟢 完全實現,包括 require.main、require.cache、require.resolve。
Response
🟢 完全實現。
Request
🟢 完全實現。
setImmediate()
🟢 完全實現。
setInterval()
🟢 完全實現。
setTimeout()
🟢 完全實現。
structuredClone()
🟢 完全實現。
SubtleCrypto
🟢 完全實現。
DOMException
🟢 完全實現。
TextDecoder
🟢 完全實現。
TextDecoderStream
🟢 完全實現。
TextEncoder
🟢 完全實現。
TextEncoderStream
🟢 完全實現。
TransformStream
🟢 完全實現。
TransformStreamDefaultController
🟢 完全實現。
URL
🟢 完全實現。
URLSearchParams
🟢 完全實現。
WebAssembly
🟢 完全實現。
WritableStream
🟢 完全實現。
WritableStreamDefaultController
🟢 完全實現。
WritableStreamDefaultWriter
🟢 完全實現。