Registry / devops / esbuild-plugin-polyfill-node

esbuild-plugin-polyfill-node

JSON →
library0.3.0jsnpmunverified

An esbuild plugin for polyfilling Node.js built-in modules and globals in browser, edge, and Deno environments. Version 0.3.0 is the latest stable release, actively maintained by cyco130. It leverages @jspm/core for polyfills and offers fine-grained control over individual polyfills via options. The plugin includes two variants: polyfillNode for general edge use and polyfillNodeForDeno which uses Deno's std/node library. Key differentiators include support for both Deno and Deno Deploy, configurable globals (Buffer, process, __dirname, __filename), and the ability to disable or replace specific polyfills with empty stubs or npm packages.

npm install esbuild-plugin-polyfill-node
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-POL
E
esbuild-plugin-polyfill-node
devopsjavascriptv0.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

polyfillNode
import { polyfillNode } from 'esbuild-plugin-polyfill-node'
const polyfillNode = require('esbuild-plugin-polyfill-node')
Default export is not supported; use named import.
polyfillNodeForDeno
import { polyfillNodeForDeno } from 'esbuild-plugin-polyfill-node'
import { polyfillNodeForDeno } from 'esbuild-plugin-polyfill-node/deno'
Both plugins are exported from the main package, no separate path needed.
polyfillNode (CommonJS)
const { polyfillNode } = require('esbuild-plugin-polyfill-node')
const polyfillNode = require('esbuild-plugin-polyfill-node').default
CommonJS destructured require works; no default export.

Shows how to use polyfillNode plugin with esbuild, disabling Buffer/process globals and enabling crypto/fs polyfills.

import { build } from 'esbuild'; import { polyfillNode } from 'esbuild-plugin-polyfill-node'; await build({ entryPoints: ['src/index.js'], bundle: true, outfile: 'dist/bundle.js', plugins: [ polyfillNode({ globals: { buffer: false, process: false }, polyfills: { crypto: true, fs: true } }) ] });
Debug
Known issues
gotchaThe 'crypto' and 'fs' polyfills are disabled by default; they must be explicitly enabled in the polyfills option to be included.
fix
Set polyfills: { crypto: true, fs: true } in plugin options.
affects: >=0.1.0
gotchaEnabling the 'Buffer' global (globals.buffer: true) will inject the buffer-es6 polyfill which is large; code like 'if (typeof Buffer !== "undefined")' will cause it to be included unnecessarily.
fix
Set globals.buffer: false unless your code explicitly uses Buffer.
affects: >=0.1.0
gotchaThe polyfillNodeForDeno plugin uses Deno's std/node library, which was removed from Deno core in v0.178.0. This plugin is only useful for Deno Deploy, not newer Deno versions.
fix
Use polyfillNodeForDeno only for Deno Deploy targets; for Deno >=0.178.0 use native node: imports.
affects: >=0.1.0
Errors
Common errors & fixes
Error: [esbuild] No matching polyfill for module 'crypto'
The 'crypto' polyfill is not enabled by default.
fix
Add { polyfills: { crypto: true } } to plugin options.
TypeError: Cannot read properties of undefined (reading 'NODE_ENV')
The 'process' global is not polyfilled by default when globals.process is false, but code expects process.env.
fix
Either set globals.process: true or use esbuild's define option: --define:process.env.NODE_ENV='production'
Error: Cannot find module 'buffer'
The buffer polyfill might be disabled but code requires Buffer.
fix
Enable buffer polyfill: set globals.buffer: true or import 'buffer' polyfill explicitly.
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies
esbuildrequiredPeer dependency; esbuild is required as the bundler.
Agent activity
6 hits · last 30 days
node
6
Resources
esbuild-plugin-polyfill-node — npm install esbuild-plugin-polyfill-node · libregistry