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

Open
#112 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

  • #115 by @mahmoodhamdi — closed without merging

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
50/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, node.js
Domain
backend

Research direction

Search the repository for require('safe-buffer').Buffer and inspect the dependency declaration. Replace the safe-buffer usage with the built-in Buffer API, remove the dependency, and verify that the project still works with its supported Node.js versions and modern ESM bundlers.

Written by the indexing model from the issue text.

Description

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!

Dominant language
JavaScript
Stars
721
Forks
141
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from auth0/node-jws

All issues in auth0/node-jws

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.