{"id":21262,"library":"esbuild-plugin-polyfill-node","title":"esbuild-plugin-polyfill-node","description":"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.","status":"active","version":"0.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/cyco130/esbuild-plugin-polyfill-node","tags":["javascript","esbuild-plugin","node-polyfill","deno","edge","typescript"],"install":[{"cmd":"npm install esbuild-plugin-polyfill-node","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-polyfill-node","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-polyfill-node","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; esbuild is required as the bundler.","package":"esbuild","optional":false}],"imports":[{"note":"Default export is not supported; use named import.","wrong":"const polyfillNode = require('esbuild-plugin-polyfill-node')","symbol":"polyfillNode","correct":"import { polyfillNode } from 'esbuild-plugin-polyfill-node'"},{"note":"Both plugins are exported from the main package, no separate path needed.","wrong":"import { polyfillNodeForDeno } from 'esbuild-plugin-polyfill-node/deno'","symbol":"polyfillNodeForDeno","correct":"import { polyfillNodeForDeno } from 'esbuild-plugin-polyfill-node'"},{"note":"CommonJS destructured require works; no default export.","wrong":"const polyfillNode = require('esbuild-plugin-polyfill-node').default","symbol":"polyfillNode (CommonJS)","correct":"const { polyfillNode } = require('esbuild-plugin-polyfill-node')"}],"quickstart":{"code":"import { build } from 'esbuild';\nimport { polyfillNode } from 'esbuild-plugin-polyfill-node';\n\nawait build({\n  entryPoints: ['src/index.js'],\n  bundle: true,\n  outfile: 'dist/bundle.js',\n  plugins: [\n    polyfillNode({\n      globals: { buffer: false, process: false },\n      polyfills: { crypto: true, fs: true }\n    })\n  ]\n});","lang":"javascript","description":"Shows how to use polyfillNode plugin with esbuild, disabling Buffer/process globals and enabling crypto/fs polyfills."},"warnings":[{"fix":"Set polyfills: { crypto: true, fs: true } in plugin options.","message":"The 'crypto' and 'fs' polyfills are disabled by default; they must be explicitly enabled in the polyfills option to be included.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Set globals.buffer: false unless your code explicitly uses Buffer.","message":"Enabling 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use polyfillNodeForDeno only for Deno Deploy targets; for Deno >=0.178.0 use native node: imports.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Add { polyfills: { crypto: true } } to plugin options.","cause":"The 'crypto' polyfill is not enabled by default.","error":"Error: [esbuild] No matching polyfill for module 'crypto'"},{"fix":"Either set globals.process: true or use esbuild's define option: --define:process.env.NODE_ENV='production'","cause":"The 'process' global is not polyfilled by default when globals.process is false, but code expects process.env.","error":"TypeError: Cannot read properties of undefined (reading 'NODE_ENV')"},{"fix":"Enable buffer polyfill: set globals.buffer: true or import 'buffer' polyfill explicitly.","cause":"The buffer polyfill might be disabled but code requires Buffer.","error":"Error: Cannot find module 'buffer'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}