{"id":12912,"library":"browserify","title":"Browserify","description":"Browserify is a JavaScript bundler that enables developers to use Node.js-style `require()` statements in client-side browser code. It recursively analyzes the `require()` calls in an application to build a single JavaScript bundle that can be served to the browser. As of April 2026, the current stable version is 17.0.1, with releases occurring periodically to address dependency updates and bug fixes, rather than a strict time-based cadence. Its key differentiator is its adherence to the CommonJS module system for the browser, allowing direct reuse of many npm modules originally written for Node.js, offering an alternative to modern ESM-focused bundlers like Webpack or Rollup for projects that prefer or are built around the CommonJS paradigm. It handles core Node.js built-in modules by providing browser-compatible polyfills.","status":"active","version":"17.0.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/browserify/browserify","tags":["javascript","browser","require","commonjs","commonj-esque","bundle","npm"],"install":[{"cmd":"npm install browserify","lang":"bash","label":"npm"},{"cmd":"yarn add browserify","lang":"bash","label":"yarn"},{"cmd":"pnpm add browserify","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Most common usage is via the command line. `npx` ensures using the locally installed version. Global installation (`npm install -g browserify`) allows direct `browserify` command.","wrong":"browserify main.js > bundle.js (if not globally installed)","symbol":"browserify CLI","correct":"npx browserify main.js -o bundle.js"},{"note":"Browserify is primarily a CommonJS module, reflecting its origins and Node.js-centric nature. While Node.js supports ESM, Browserify itself is best consumed via `require()` in build scripts.","wrong":"import browserify from 'browserify';","symbol":"browserify (programmatic)","correct":"const browserify = require('browserify');"},{"note":"Transforms (like `envify`, `babelify`) are applied to modules. When used programmatically, transforms are typically `require`d and passed as functions or strings.","wrong":"b.transform('some-transform'); (without require/import)","symbol":"Transform API","correct":"b.transform(require('some-transform'));"}],"quickstart":{"code":"const fs = require('fs');\nconst browserify = require('browserify');\n\n// main.js - This would typically be a separate file\nconst mainJsContent = `\nvar foo = require('./foo.js');\nvar bar = require('../lib/bar.js');\nvar gamma = require('gamma'); // Assuming 'gamma' is an npm package\n\nvar elem = { textContent: '' }; // Mock document.getElementById('result') for Node.js context\n// In a real browser, this would be: var elem = document.getElementById('result');\n\nvar x = foo(100) + bar('baz');\nelem.textContent = gamma(x);\n\nconsole.log('Result:', elem.textContent);\n`;\n\n// foo.js - Another module\nconst fooJsContent = `\nmodule.exports = function (n) { return n * 111; };\n`;\n\n// lib/bar.js - Another module in a subdirectory\nconst barJsContent = `\nmodule.exports = function (s) { return s.length; };\n`;\n\n// Create dummy files for the example to run\nfs.writeFileSync('main.js', mainJsContent);\nfs.writeFileSync('foo.js', fooJsContent);\nfs.writeFileSync('lib', '', { flag: 'wx' }, (err) => {\n  if (err && err.code !== 'EEXIST') throw err;\n  fs.writeFileSync('lib/bar.js', barJsContent);\n});\n\n\nconst b = browserify('./main.js', {\n  // Optionally include source maps for debugging\n  debug: true\n});\n\n// You might add transforms here, e.g., b.transform('babelify');\n\nb.bundle((err, buf) => {\n  if (err) {\n    console.error('Browserify error:', err);\n    return;\n  }\n  console.log('Bundle created successfully! Writing to bundle.js');\n  fs.writeFileSync('bundle.js', buf.toString());\n  console.log('To run this bundle in a browser: <script src=\"bundle.js\"></script>');\n  \n  // Cleanup dummy files (optional)\n  fs.unlinkSync('main.js');\n  fs.unlinkSync('foo.js');\n  fs.unlinkSync('lib/bar.js');\n  fs.rmdirSync('lib');\n});\n\n","lang":"javascript","description":"This quickstart demonstrates programmatically bundling a simple application with `browserify`, showing how it resolves internal `require()` calls and outputs a single JavaScript file. It creates hypothetical module files and then bundles `main.js` into `bundle.js`."},"warnings":[{"fix":"Review any custom logic interacting with `EventEmitter` or `stream` polyfills. Update code to be compatible with Node.js 10+ stream API or `events` v3.x.","message":"Major internal dependency upgrades in v17.0.0 changed underlying APIs for 'events', 'path-browserify', and 'stream-browserify'. Projects relying on deeply introspecting or extending these polyfills might experience issues. Specifically, `EventEmitter` instances now have an `off()` method, and `require('stream')` matches Node.js 10+ API.","severity":"breaking","affected_versions":">=17.0.0"},{"fix":"If IE10 or older browser support is critical, either pin Browserify to a version prior to 16.4.0 (e.g., 16.3.0) or implement custom polyfills/workarounds for HTTP/HTTPS functionality for those specific environments.","message":"The `stream-http` dependency, upgraded in v16.4.0, dropped support for Internet Explorer 10 and below. Applications targeting these legacy browsers will no longer function correctly if they rely on `http` or `https` browser polyfills provided by Browserify.","severity":"breaking","affected_versions":">=16.4.0"},{"fix":"Only use `--noparse` for files that are truly self-contained or explicitly global, and do not contain internal `require()` statements that Browserify needs to resolve. Verify that all dependencies of `noparse`d files are either globally available or included through other means.","message":"Using the `--noparse` option (or `options.noparse` programmatically) prevents Browserify from parsing the specified files. While this can significantly speed up builds for large libraries (e.g., jQuery), it also means that any `require()` calls *within* those `noparse`d files will *not* be resolved or bundled by Browserify, potentially leading to runtime errors if those dependencies are not externally provided.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Be aware that Browserify's polyfills aim for a baseline compatibility. For specific, cutting-edge Node.js API features, consider if a custom polyfill or an alternative bundling approach is necessary. Always test your bundled code thoroughly in target browser environments.","message":"Browserify's support for Node.js 0.8 (as indicated in older version dependencies) means it prioritizes broad compatibility over the latest Node.js features. While it polyfills many Node.js built-ins for the browser, users expecting behavior or APIs from very recent Node.js versions might find discrepancies or missing features in the polyfilled modules.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure the module is installed (e.g., `npm install some-module`) and correctly referenced with its package name or a valid relative/absolute path. Check for typos in the `require()` path.","cause":"A `require()` statement refers to a module that Browserify cannot locate in `node_modules` or via a relative path.","error":"Error: Cannot find module 'some-module'"},{"fix":"Use the `--insert-globals` (`--ig`) or `--detect-globals` (`--dg`) options when bundling via CLI, or `insertGlobals: true` / `detectGlobals: true` in programmatic options, to ensure Browserify adds polyfills for Node.js globals like `process`.","cause":"Code expects the Node.js `process` global to be available in the browser, but Browserify's global detection or insertion was not enabled or overridden.","error":"ReferenceError: process is not defined"},{"fix":"Ensure global insertion or detection is enabled via `--insert-globals` / `--detect-globals` CLI options or programmatic `insertGlobals: true` / `detectGlobals: true` options. Browserify's default behavior usually includes `Buffer` polyfills, so check if any transforms or configurations are interfering.","cause":"Similar to `process`, code relies on the Node.js `Buffer` global without it being polyfilled or detected by Browserify.","error":"ReferenceError: Buffer is not defined"},{"fix":"If installed locally in a project, use `npx browserify` (recommended). To make `browserify` available globally, run `npm install -g browserify`.","cause":"The `browserify` executable is not in the system's PATH, typically because it was not installed globally or `npx` was not used for a local installation.","error":"browserify: command not found"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"browserify"}