Bun 旨在完全相容 Node.js API。大多數針對 Node.js
環境的 npm
套件都能在 Bun 中直接使用;最能確定方法就是嘗試看看。
此頁面會定期更新,以反映 Bun 最新版本的相容性狀態。以下資訊反映 Bun 與 Node.js v20 的相容性。如果你遇到特定套件的任何錯誤,請 開啟問題。開啟相容性錯誤的問題有助於我們優先處理接下來要處理的工作。
內建模組
node:assert
🟢 完全實作。
node:async_hooks
🟡 僅實作 AsyncLocalStorage
和 AsyncResource
。AsyncResource
缺少 bind
。
node:buffer
🟢 完全實作。
node:child_process
🟡 缺少 Stream
stdio、proc.gid
proc.uid
。IPC 無法傳送 socket 句柄,且僅能與其他 bun
程序運作。
node:cluster
🔴 未實作。
node:console
🟢 完全實作。
node:crypto
🟡 缺少 Certificate
ECDH
X509Certificate
checkPrime
checkPrimeSync
diffieHellman
generatePrime
generatePrimeSync
getCipherInfo
getFips
hkdf
hkdfSync
secureHeapUsed
setEngine
setFips
部分方法尚未最佳化。
node:dgram
🟡 缺少 setBroadcast
setTTL
setMulticastTTL
setMulticastLoopback
setMulticastInterface
addMembership
dropMembership
addSourceSpecificMembership
dropSourceSpecificMembership
node:diagnostics_channel
🟢 完全實作。
node:dns
🟡 缺少 cancel
setServers
getDefaultResultOrder
node:domain
🟡 缺少 Domain
active
node:events
🟡 缺少 addAbortListener
events.getMaxListeners
node:fs
🟡 缺少 statfs
statfsSync
, opendirSync
。Dir
已部分實作。
node:http
🟢 完全實作。
node:http2
🟡 支援用戶端,但不支援伺服器。
node:https
🟢 完全實作。
node:inspector
🔴 未實作。
node:module
🟡 缺少 runMain
syncBuiltinESMExports
, Module#load()
。嘗試覆寫或修補模組快取會失敗。
node:net
🟡 缺少 BlockList
SocketAddress
Stream
node:os
🟢 完全實作。
node:path
🟢 完全實作。
node:perf_hooks
🟡 缺少 createHistogram
monitorEventLoopDelay
。建議使用 performance
全域變數,而非 perf_hooks.performance
。
node:process
🟡 參閱 process
全域。
node:punycode
🟢 已完全實作。已由 Node.js 棄用。
node:querystring
🟢 完全實作。
node:readline
🟢 完全實作。
node:repl
🔴 未實作。
node:stream
🟡 缺少 getDefaultHighWaterMark
setDefaultHighWaterMark
toWeb
node:string_decoder
🟢 完全實作。
node:sys
🟡 參閱 node:util
。
node:test
🔴 未實作。請改用 bun:test
。
node:timers
🟢 建議改用全域 setTimeout
等。
node:tls
🟡 缺少 tls.createSecurePair
。
node:trace_events
🔴 未實作。
node:tty
🟢 完全實作。
node:url
🟢 完全實作。
node:util
🟡 缺少 MIMEParams
MIMEType
aborted
debug
getSystemErrorMap
getSystemErrorName
transferableAbortController
transferableAbortSignal
stripVTControlCharacters
node:v8
🔴 serialize
和 deserialize
使用 JavaScriptCore 的線路格式,而不是 V8 的線路格式。否則,未實作。對於剖析,請改用 bun:jsc
。
node:vm
🟡 核心功能運作正常,但未實作實驗性 VM ES 模組,包括 vm.Module
、vm.SourceTextModule
、vm.SyntheticModule
、importModuleDynamically
和 vm.measureMemory
。尚未實作 timeout
、breakOnSigint
、cachedData
等選項。對於具有情境化選項的 this
值,有一個錯誤,其沒有正確的原型。
node:wasi
🟡 部分實作。
node:worker_threads
🟡 Worker
不支援下列選項:eval
stdin
stdout
stderr
trackedUnmanagedFds
resourceLimits
。缺少 markAsUntransferable
moveMessagePortToContext
getHeapSnapshot
。
node:zlib
🟡 缺少 BrotliCompress
BrotliDecompress
brotliCompressSync
brotliDecompress
brotliDecompressSync
createBrotliCompress
createBrotliDecompress
。未最佳化。
全域變數
下表列出 Node.js 和 Bun 目前相容性狀態所實作的所有全域變數。
AbortController
🟢 完全實作。
AbortSignal
🟢 完全實作。
Blob
🟢 完全實作。
Buffer
🟡 base64
和 base64url
編碼實作不完整。
ByteLengthQueuingStrategy
🟢 完全實作。
__dirname
🟢 完全實作。
__filename
🟢 完全實作。
atob()
🟢 完全實作。
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
🟡 缺少 domain
hasUncaughtExceptionCaptureCallback
initgroups
resourceUsage
setUncaughtExceptionCaptureCallback
setegid
seteuid
setgid
setgroups
setuid
allowedNodeEnvironmentFlags
getActiveResourcesInfo
setActiveResourcesInfo
moduleLoadList
setSourceMapsEnabled
channel
。process.binding
已部分實作。
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
🟡 URL.createObjectURL
遺失。請參閱 問題 #3925
URLSearchParams
🟢 完全實作。
WebAssembly
🟢 完全實作。
WritableStream
🟢 完全實作。
WritableStreamDefaultController
🟢 完全實作。
WritableStreamDefaultWriter
🟢 完全實作。