Registry / devops / esbuild-node-builtin

esbuild-node-builtin

JSON →
library0.1.1jsnpmunverified

esbuild plugin to polyfill Node.js built-in modules when bundling for the browser. Version 0.1.1, stable but rarely updated. Integrates polyfills from rollup-plugin-polyfill-node with tree-shaking support, unlike alternatives that include entire modules. It uses esbuild's inject API to handle globals like 'global', 'process', and optionally 'Buffer'. Requires esbuild as a peer dependency and uses rollup-plugin-polyfill-node internally (a no-op dependency to avoid errors).

npm install esbuild-node-builtin
INSTALL
IMPORT
SIG · ESBUILD-NODE-BUILT
E
esbuild-node-builtin
devopsjavascriptv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

nodeBuiltin
import { nodeBuiltin } from 'esbuild-node-builtin'
import nodeBuiltin from 'esbuild-node-builtin'
Exported as named export only; default import will not work.
nodeBuiltin
const { nodeBuiltin } = require('esbuild-node-builtin')
const nodeBuiltin = require('esbuild-node-builtin')
CJS require destructuring is required; plain require returns an object with the named export.
EsbuildNodeBuiltinOptions
import type { EsbuildNodeBuiltinOptions } from 'esbuild-node-builtin'
Type import for the options interface; only needed with TypeScript.

Demonstrates basic usage of the plugin with esbuild bundling for browser, using default options to polyfill 'global' and 'process'.

import { nodeBuiltin } from 'esbuild-node-builtin'; import esbuild from 'esbuild'; await esbuild.build({ entryPoints: ['src/index.js'], bundle: true, outfile: 'dist/bundle.js', platform: 'browser', plugins: [nodeBuiltin()], });
Debug
Known issues
gotchaThe package depends on rollup-plugin-polyfill-node, but rollup is not actually needed at runtime. This can cause confusion if you try to install rollup as a dependency.
fix
Ignore the rollup dependency; it is used only internally. Do not install rollup unless required for other projects.
affects: >=0.0.0
gotchaThe 'injectBuffer' option is disabled by default because it is large and not tree-shakable. Enabling it may significantly increase bundle size.
fix
Only set injectBuffer: true if you absolutely need the Buffer global and accept the size cost.
affects: >=0.0.0
deprecatedThe 'exclude' option uses a string array to disable proxying certain builtins. This API may change in future versions.
fix
Check the README on GitHub for the latest API if upgrading.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'rollup-plugin-polyfill-node'
The package has a dependency on rollup-plugin-polyfill-node, which may not be installed if using a strict package manager or if node_modules are pruned.
fix
Ensure rollup-plugin-polyfill-node is installed (it is a regular dependency, not optional). Run: pnpm add -D esbuild-node-builtin or npm install esbuild-node-builtin --save-dev
TypeError: esbuild_node_builtin_1.nodeBuiltin is not a function
Using a default import instead of a named import.
fix
Use named import: import { nodeBuiltin } from 'esbuild-node-builtin'
Error: The plugin "esbuild-node-builtin" is not a function
Attempting to use the plugin without calling the factory function, e.g. plugins: [nodeBuiltin] instead of plugins: [nodeBuiltin()].
fix
Invoke the function: plugins: [nodeBuiltin()]
Error: Build failed with 1 error: error: Could not resolve "crypto"
The plugin may not cover all Node builtins, or the builtin is not polyfilled by default.
fix
Check if the builtin is polyfilled; if not, use a separate polyfill package and add to the 'exclude' option to avoid double bundling.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
esbuildrequiredPeer dependency required for the plugin to work
rollup-plugin-polyfill-nodeoptionalInternal dependency for polyfills, but rollup is not actually needed at runtime
Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
esbuild-node-builtin — npm install esbuild-node-builtin · libregistry