Registry / devops / esmangle2

esmangle2

JSON →
library1.0.11jsnpmunverified

esmangle is a ECMAScript code mangler and minifier that operates on Mozilla Parser API AST. It is part of the estools ecosystem (esprima, escodegen) and is designed to work with AST-based transformations for JavaScript minification. Version 1.0.11 is the latest stable release, but the project appears to be unmaintained (last release in 2014). Key differentiators: supports both Node.js and browser environments, provides optimize and mangle passes, and integrates with esprima for parsing and escodegen for code generation.

npm install esmangle2
INSTALL
IMPORT
SIG · ESMANGLE2
E
esmangle2
devopsjavascriptv1.0.11
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.

esmangle
import esmangle from 'esmangle'
const esmangle = require('esmangle')
As an old package, it uses CommonJS exports; default import works in modern bundlers, but require() is also valid.
mangle
import { mangle } from 'esmangle'
const { mangle } = require('esmangle')
mangle is a named export; works in both ESM and CJS environments.
optimize
import { optimize } from 'esmangle'
import optimize from 'esmangle'
optimize is a named export, not a default export. Using default import will give undefined.

This demonstrates the full pipeline: parsing code with esprima, optimizing and mangling with esmangle, then generating minified code with escodegen.

import * as esprima from 'esprima'; import * as escodegen from 'escodegen'; import { mangle, optimize } from 'esmangle'; const code = 'function square(n) { return n * n; }'; const ast = esprima.parseScript(code); const optimized = optimize(ast, null); const mangled = mangle(optimized); const result = escodegen.generate(mangled, { format: { renumber: true, hexadecimal: true, escapeless: true, compact: true, semicolons: false, parentheses: false } }); console.log(result);
Debug
Known issues
deprecatedesmangle is unmaintained and no longer updated. Use modern minifiers like terser or esbuild instead.
fix
Migrate to terser or esbuild for active development and ES6+ support.
affects: all
gotchaesmangle only works with ES5 code. It does not support ES6+ syntax (e.g., arrow functions, classes). Parsing modern code with esprima will fail or produce incorrect results.
fix
Transpile modern code to ES5 before using esmangle, or switch to a minifier that supports ES6+.
affects: <=1.0.11
gotchaThe CLI command 'esmangle' may not be globally available and requires local install.
fix
Run via npx or install locally: npx esmangle file.js
affects: all
gotchaThe browser build is only available for old browsers (no module support). Download the pre-built file from the GitHub pages.
fix
Use a CDN link or include script tag. Note that it pollutes the global scope.
affects: all
Errors
Common errors & fixes
Cannot find module 'esmangle'
The package is not installed or is missing from node_modules.
fix
Run 'npm install esmangle' or add it to package.json.
esprima.parse is not a function
Using esprima's parseScript incorrectly; esprima v4+ uses parseScript instead of parse.
fix
Use 'esprima.parseScript(code)' for modules or 'esprima.parseScript(code, { jsx: true })' if using JSX. For ES5, 'esprima.parse(code)' works but is deprecated.
esmangle.mangle is not a function
The imported object may be incorrect due to CommonJS vs ESM mismatch.
fix
Ensure you use the correct named import: 'const { mangle } = require("esmangle");' or 'import { mangle } from "esmangle";'
Upgrade
Version history
1.0.11latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
esmangle2 — npm install esmangle2 · libregistry