Registry / devops / uglify-js-export

uglify-js-export

JSON →
library3.19.3jsnpmunverified

A thin wrapper that re-exports UglifyJS as an ES module, primarily for use with browserify transforms. Current stable version is 3.19.3. The package follows UglifyJS releases closely and provides TypeScript types. Key differentiators: it allows CommonJS-based tooling like browserify to consume UglifyJS natively without manual import hacks, including the internal parse API and source map support. It ships with full UglifyJS 3.19.3 functionality, correctly exposing both the minify function and parse/AST utilities. Release cadence matches UglifyJS upstream (approximately yearly). This package is a simple re-export, not a fork or alternative minifier.

npm install uglify-js-export
INSTALL
IMPORT
SIG · UGLIFY-JS-EXPORT
U
uglify-js-export
devopsjavascriptv3.19.3
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.

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'.
fix
Switch 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.
fix
Use 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.
fix
When 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).
fix
If 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.
fix
Use 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.
fix
Change 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.
fix
Run: 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.
fix
Use 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'.
fix
Ensure your project is configured for ESM (e.g., set 'type': 'module' in package.json) or use a transpiler like Babel.
Upgrade
Version history
3.19.3latest on npm
Audit
Dependencies
uglify-jsrequiredThe original UglifyJS library is bundled as the core implementation.
Agent activity
2 hits · last 30 days
node
2
Resources
uglify-js-export — npm install uglify-js-export · libregistry