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.
UglifyJS (default import)
✓ import UglifyJS from 'uglify-js-export';
✗ import * as UglifyJS from 'uglify-js-export';
Default import gives you the entire UglifyJS object including minify, parse, Ast, etc.
minify (named import)
✓ import { minify } from 'uglify-js-export';
✗ const { minify } = require('uglify-js-export');
Named exports are available for individual functions like minify, parse, etc. The package is ESM-only, so require() will fail.
parse (named import)
✓ import { parse } from 'uglify-js-export';
✗ import UglifyJS from 'uglify-js-export'; const { parse } = UglifyJS;
You can destructure named exports directly. The default export also contains these methods, but named imports optimize tree-shaking.
Demonstrates minifying a simple function and accessing the parse API, including error handling.
import UglifyJS from 'uglify-js-export';
const code = `function add(first, second) {
return first + second;
}`;
const result = UglifyJS.minify(code);
if (result.error) {
console.error('Minification error:', result.error);
} else {
console.log(result.code);
// Output: function add(n,d){return n+d}
}
// Also access the parser:
const ast = UglifyJS.parse(code);
console.log('AST body length:', ast.body.length);
// Output: AST body length: 1
Debug
Known issues
breakingPackage is ESM-only since version 3.17.0. Using require() will throw 'ERR_REQUIRE_ESM'.fixSwitch to import syntax or use dynamic import: const UglifyJS = await import('uglify-js-export'); affects: >=3.17.0
deprecatedThe export of 'UglifyJS' as a CommonJS module was removed in v3.15.0.fixUse ESM import: import UglifyJS from 'uglify-js-export';
affects: >=3.15.0
gotchaThe package re-exports the entire UglifyJS object; calling UglifyJS.minify() with options like 'sourceMap' may behave differently if the host environment lacks Buffer or fs.fixWhen using in browser, avoid source map generation options unless you polyfill Buffer.
affects: *
gotchaTypeScript type definitions are included but may not cover all internal UglifyJS types (e.g., AST node types).fixIf you need full type coverage, install '@types/uglify-js' separately.
affects: *
deprecatedThe 'fromString' and 'uglify' export aliases were removed in v3.12.0; use named exports directly.fixUse import { minify, parse } from 'uglify-js-export'; affects: >=3.12.0 <3.15.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/uglify-js-export/index.js not supported.
Using require() instead of import in a Node.js version that supports ESM.
fixChange require('uglify-js-export') to import UglifyJS from 'uglify-js-export'; or use dynamic import. Cannot find module 'uglify-js-export'
Package not installed or typo in import path.
fixRun: npm install uglify-js-export. Then import correctly: import UglifyJS from 'uglify-js-export';
TypeError: UglifyJS.minify is not a function
Incorrectly importing the package (e.g., import * as UglifyJS) or using an older version that exports a different shape.
fixUse default import: import UglifyJS from 'uglify-js-export'; and ensure version >=3.0.0.
SyntaxError: Unexpected token 'export'
Using a bundler or Node version that does not support ES modules, or the package.json lacks 'type': 'module'.
fixEnsure your project is configured for ESM (e.g., set 'type': 'module' in package.json) or use a transpiler like Babel.
Audit
Dependencies
uglify-jsrequiredThe original UglifyJS library is bundled as the core implementation.