amark/gun · warning

new SafeBuffer() is depreciated, please use SafeBuffer.from(

Error message

new SafeBuffer() is depreciated, please use SafeBuffer.from()

What it means

This is not a thrown error but a console.warn emitted by SEA's SafeBuffer constructor in sea/buffer.js. The SafeBuffer constructor is kept only for API compatibility with Node's 'safe-buffer' package; calling it with `new SafeBuffer(...)` (or as a plain function) logs this deprecation notice and transparently delegates to SafeBuffer.from(...), so behavior still works but is discouraged. The message intentionally mirrors the feross/safe-buffer update where constructor calls were replaced by static from()/alloc() methods.

Source

Thrown at sea/buffer.js:11

;(function(){

    require('./base64');
    // This is Buffer implementation used in SEA. Functionality is mostly
    // compatible with NodeJS 'safe-buffer' and is used for encoding conversions
    // between binary and 'hex' | 'utf8' | 'base64'
    // See documentation and validation for safe implementation in:
    // https://github.com/feross/safe-buffer#update
    var SeaArray = require('./array');
    function SafeBuffer(...props) {
      console.warn('new SafeBuffer() is depreciated, please use SafeBuffer.from()')
      return SafeBuffer.from(...props)
    }
    SafeBuffer.prototype = Object.create(Array.prototype)
    Object.assign(SafeBuffer, {
      // (data, enc) where typeof data === 'string' then enc === 'utf8'|'hex'|'base64'
      from() {
        if (!Object.keys(arguments).length || arguments[0]==null) {
          throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
        }
        const input = arguments[0]
        let buf
        if (typeof input === 'string') {
          const enc = arguments[1] || 'utf8'
          if (enc === 'hex') {
            const bytes = input.match(/([\da-fA-F]{2})/g)
            .map((byte) => parseInt(byte, 16))
            if (!bytes || !bytes.length) {
              throw new TypeError('Invalid first argument for type \'hex\'.')

View on GitHub (pinned to 552227599d)

Solutions

  1. Replace `new SafeBuffer(...)` with `SafeBuffer.from(...)` using the same arguments (e.g. SafeBuffer.from(str,'utf8')).
  2. Use SafeBuffer.alloc(len) when you need a zero-filled buffer of a given length instead of constructing one.
  3. Grep the project for `new SafeBuffer` and fix all occurrences; the constructor path may be removed in future SEA versions.
  4. If this warning comes from a dependency, update that dependency to a SEA version using the from() API.

Example fix

// before\nvar buf = new SafeBuffer('hello', 'utf8');\n// after\nvar buf = SafeBuffer.from('hello', 'utf8');
Defensive patterns

Strategy: fallback

Validate before calling

// Prefer the supported API surface\nif (typeof SafeBuffer.from !== 'function') throw new Error('SEA SafeBuffer.from unavailable');\n// Use SafeBuffer.from(data, enc) instead of new SafeBuffer(data, enc)\nvar buf = SafeBuffer.from('hello', 'utf8');

Type guard

function isSeaBuffer(x){ return x instanceof SafeBuffer || (Array.isArray(x) && typeof x.toString === 'function' && x.constructor && /SeaArray|SafeBuffer/.test(String(x.constructor.name))); }

Try / catch

try {\n  var buf = SafeBuffer.from(input, 'utf8');\n} catch (e) {\n  // SafeBuffer.from throws TypeError on null/invalid input\n  console.error('SEA buffer conversion failed:', e.message);\n}

Prevention

When it happens

Trigger: Calling `new SafeBuffer(data, enc)` or `SafeBuffer(...)` anywhere in code using Gun's SEA module instead of `SafeBuffer.from(data, enc)`; typically in crypto helpers converting between binary and hex/utf8/base64. Also triggered by code copied from older Node Buffer-style usage patterns.

Common situations: Developers porting Node code that uses `new Buffer(...)` semantics to browser SEA code; older third-party snippets or plugins written against early SEA versions; accidental search-and-replace of Buffer with SafeBuffer keeping the `new` keyword.

Related errors


AI-assisted analysis of amark/gun@552227599d (2026-09-02). Data as JSON: /api/errors/ef77e71969e7716a. Report an issue: GitHub.