CommonJS Everywhere Bundler
raw JSON →commonjs-everywhere (cjsify) is a browser bundler designed for CommonJS modules, providing features like source map generation from minified bundles back to original source code, module aliasing for browser-specific overrides, and an extensible architecture to support various compile-to-JavaScript languages. Its current stable version is 0.9.7, and it appears to be unmaintained given its reliance on Node.js 0.8.x, 0.9.x, or 0.10.x (versions that were released over a decade ago and are long End-of-Life). Key differentiators in its time included robust source map support from minified to original sources, the ability to define custom handlers for non-JavaScript files (such as CoffeeScript and JSON, which were included by default), and an efficient watch mode that only rebuilt changed dependencies. It served as an early alternative to tools like Browserify for enabling Node.js-style module loading in browser environments.
Common errors
error Error: Cannot find module 'commonjs-everywhere' ↓
commonjs-everywhere is installed locally (npm install commonjs-everywhere) or globally (npm install -g commonjs-everywhere). Check the require() path for accuracy. error Error: 'require' not defined ↓
cjsify and then processing its output. If you tried to use import, switch to const cjsify = require('commonjs-everywhere');. error SyntaxError: Cannot use import statement outside a module ↓
const cjsify = require('commonjs-everywhere'); instead of import. Warnings
breaking The package is explicitly compatible only with very old Node.js versions (0.8.x, 0.9.x, 0.10.x). It is highly unlikely to run on modern Node.js versions without significant issues or failure. ↓
abandoned commonjs-everywhere is no longer actively maintained. The last release was several years ago, and its dependencies and underlying technologies are outdated. ↓
gotcha When using the programmatic interface (`cjsify(entryPoint, root, options)`), the function returns a SpiderMonkey AST (Abstract Syntax Tree), not executable JavaScript code. You must use a separate tool like `escodegen` to convert the AST into a JavaScript string. ↓
gotcha Using unmaintained software, especially build tools, can introduce security vulnerabilities through unpatched dependencies, deprecated APIs, or inherent flaws that will not receive updates. ↓
Install
npm install commonjs-everywhere yarn add commonjs-everywhere pnpm add commonjs-everywhere Imports
- cjsify wrong
import { cjsify } from 'commonjs-everywhere';correctconst cjsify = require('commonjs-everywhere'); - CLI wrong
commonjs-everywhere <options>correctnpx commonjs-everywhere <options>
Quickstart
# Create dummy files for demonstration
mkdir -p cjs-app/src
echo 'module.exports = "Hello from dep!";' > cjs-app/src/dep.js
echo 'const dep = require("./dep"); module.exports = () => `Main output: ${dep}`;' > cjs-app/src/entry-file.js
# Navigate into the app directory
cd cjs-app
# Bundle the entry file, export 'MyLibrary', and create a source map
# This will output the bundled code to stdout
npx commonjs-everywhere src/entry-file.js --export MyLibrary --source-map my-library.js.map >my-library.js
# To see the output
cat my-library.js
cat my-library.js.map
# Clean up (optional)
cd ..
rm -rf cjs-app