esbuild Node.js Builtins Plugin

raw JSON →
0.1.0 verified Fri May 01 auth: no javascript abandoned

esbuild-node-builtins is a plugin for esbuild that provides polyfilled Node.js built-in modules (e.g., 'fs', 'path', 'crypto') for browser or other non-Node environments. Version 0.1.0 is the initial stable release, with no further updates or release cadence documented. It wraps browserify's 'node-libs-browser' to polyfill core modules, enabling bundling of Node-centric code for the browser with esbuild. Unlike esbuild's native 'platform: node', this plugin actually inlines polyfills; it is a simple integration but has no active maintenance and may be superseded by esbuild's own node polyfills or other plugins like 'esbuild-plugin-polyfill-node'.

error Cannot find module 'esbuild-node-builtins'
cause Package not installed or missing from node_modules
fix
Run 'npm install esbuild-node-builtins' or 'yarn add esbuild-node-builtins'
error TypeError: (intermediate value).nodeBuiltIns is not a function
cause Wrong import style: using default import instead of named destructuring
fix
Use 'const { nodeBuiltIns } = require("esbuild-node-builtins")' (note curly braces)
error Error: Could not resolve 'fs' (or similar built-in module)
cause nodeBuiltIns plugin not registered in esbuild's plugins array
fix
Add nodeBuiltIns() to the plugins array and ensure esbuild is configured with platform: 'browser'
deprecated Package is no longer maintained; use esbuild-plugin-polyfill-node or esbuild's native node polyfill via platform: 'node'
fix Switch to 'esbuild-plugin-polyfill-node' (npm) or use esbuild's native handling by setting platform: 'node'.
gotcha Cannot use ES module import syntax; package requires CommonJS require()
fix Use require() or dynamic import() with .mjs extension / type: module? Not recommended.
gotcha Not all Node.js built-ins are polyfilled; relies on node-libs-browser which may be incomplete
fix Test your code thoroughly; consider contributing to node-libs-browser or using a more comprehensive polyfill.
npm install esbuild-node-builtins
yarn add esbuild-node-builtins
pnpm add esbuild-node-builtins

Shows how to require and use the nodeBuiltIns plugin in an esbuild build script for browser bundling.

const { build } = require('esbuild');
const { nodeBuiltIns } = require('esbuild-node-builtins');

build({
  entryPoints: ['./app.js'],
  bundle: true,
  outfile: './out.js',
  platform: 'browser',
  plugins: [nodeBuiltIns()],
}).catch(() => process.exit(1));