ERR_BUFFER_CONTEXT_NOT_AVAILABLE
Node.jsERRORCriticalBufferHIGH confidence

Buffer is not available in the current V8 context

Production Risk

Low — only affects native addon or vm context code.

What this means

Thrown when Node.js Buffer APIs are called from native addon code that does not have access to the Node.js environment in the current V8 context. This happens when a native addon attempts to create a Buffer outside of a proper Node.js execution context, for example in a V8 sandbox or a context created without the Node.js bootstrap.

Why it happens
  1. 1Native addon creating a Buffer from a V8 context not initialised by Node.js
  2. 2Using Node.js Buffer APIs in a vm.Context without proper Node.js bindings
  3. 3napi_create_buffer called from a worker or context without Buffer support
How to reproduce

Triggered from native (C++) addon code when Buffer allocation is attempted in a context lacking Node.js bindings.

trigger — this will error
trigger — this will error
// This error originates in native C++ addons, not JavaScript
// Simulated: calling Buffer.allocUnsafe from a bare vm context
const vm = require('vm');
const ctx = vm.createContext({});
vm.runInContext('Buffer.allocUnsafe(10)', ctx); // Buffer not available

expected output

Error [ERR_BUFFER_CONTEXT_NOT_AVAILABLE]: Buffer is not available in the current context

Fix

Pass a Buffer reference from the main context into the vm context

WHEN When you need Buffer inside a vm context

Pass a Buffer reference from the main context into the vm context
const vm = require('vm');
const ctx = vm.createContext({ Buffer });
vm.runInContext('Buffer.allocUnsafe(10)', ctx); // now available

Why this works

Explicitly injecting the Buffer constructor into the context makes it available for allocation.

Code examples
Triggerjs
// This error originates in native C++ addons, not JavaScript
// Simulated: calling Buffer.allocUnsafe from a bare vm context
const vm = require('vm');
const ctx = vm.createContext({});
vm.runInContext('Buffer.allocUnsafe(10)', ctx); // Buffer not available  // this triggers ERR_BUFFER_CONTEXT_NOT_AVAILABLE
Handle in try/catchjs
try {
  // operation that may throw ERR_BUFFER_CONTEXT_NOT_AVAILABLE
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_BUFFER_CONTEXT_NOT_AVAILABLE') {
    console.error('ERR_BUFFER_CONTEXT_NOT_AVAILABLE:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_buffer_context_not_available(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Assume Buffer is globally available in all V8 contexts

Only contexts bootstrapped by Node.js have the Buffer binding; bare vm contexts do not.

Same error in other languages
Sources
Official documentation ↗

Node.js Error Codes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors