Search code examples
node.jselectronv8

How to use Buffer.from in electron 21+


In Electron 21+, electron is using v8 memory cage. This is a fantastic move forward to reduce various bugs and enable performance of electron apps.

However, this seems to be causing an issue where I can't use Buffer.from. An example:

const buffer = Buffer.from(base64Image, `base64`)

This code throws an error:

[71637:1207/115131.065252:ERROR:node_bindings.cc(149)] Fatal error in V8: v8_ArrayBuffer_NewBackingStore When the V8 Sandbox is enabled, ArrayBuffer backing stores must be allocated inside the sandbox address space. Please use an appropriate ArrayBuffer::Allocator to allocate these buffers, or disable the sandbox.

Is there a way to keep the sandbox and keep using buffers?


Solution

  • Looks like this will be fixed in Electron 21+ with this PR (and its siblings)