Skip to content

Remove unnecessary safe-buffer dependency (use Node.js built-in Buffer API) #112

Description

@hdsuperman

Hi, I noticed that the project depends on safe-buffer. This dependency was mainly needed for very old Node.js versions (<6) that didn’t support the modern Buffer APIs.

Since all actively supported Node.js versions now include Buffer.from and Buffer.alloc natively, the safe-buffer dependency is no longer necessary. Removing it would help reduce install size and dependency tree complexity.

Additionally, safe-buffer can cause issues in modern ESM builds:

  • The package relies on require("buffer") internally.
  • When bundled as ESM (e.g. with esbuild/rollup/webpack), this leads to runtime errors such as
    Error: Dynamic require of "buffer" is not supported.

Suggested change:

  • Replace require('safe-buffer').Buffer with the built-in Buffer global.
  • Drop safe-buffer from dependencies.

This should be fully backwards-compatible for all currently supported Node.js versions (>=12, >=14, >=16, etc.).

Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions