ERR_BUFFER_CONTEXT_NOT_AVAILABLE


尝试从 addon 或嵌入器代码创建一个 Node.js Buffer 实例时,所处的 JS 引擎上下文并未关联到 Node.js 实例。传递给 Buffer 方法的数据在方法返回时将已被释放。

【An attempt was made to create a Node.js Buffer instance from addon or embedder code, while in a JS engine Context that is not associated with a Node.js instance. The data passed to the Buffer method will have been released by the time the method returns.】

遇到此错误时,创建 Buffer 实例的一个可能替代方法是创建一个普通的 Uint8Array,两者的区别仅在于生成对象的原型。Uint8Array 通常可以在所有接受 Buffer 的 Node.js 核心 API 中使用;它们在所有上下文中都可用。

【When encountering this error, a possible alternative to creating a Buffer instance is to create a normal Uint8Array, which only differs in the prototype of the resulting object. Uint8Arrays are generally accepted in all Node.js core APIs where Buffers are; they are available in all Contexts.】