Registry / devops / minify-xml

minify-xml

JSON →
library4.5.2jsnpmunverified

A fast, regex-based XML minifier for Node.js (v4.5.2). Removes comments, collapses whitespace in tags, shortens unused namespace declarations, and collapses empty elements. Supports streaming for large files (>2 GiB). Ships TypeScript types. Lightweight alternative to pretty-data, with more aggressive tag-level minification. Released regularly on npm. Requires Node.js >=16.

npm install minify-xml
INSTALL
IMPORT
SIG · MINIFY-XML
M
minify-xml
devopsjavascriptv4.5.2
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.

minifyXML (default)
import minifyXML from 'minify-xml'
import { minify } from 'minify-xml'
Default import is the main minify function. Named export `minify` also exists as an alias, but default is preferred.
minify
import { minify } from 'minify-xml'
const { minify } = require('minify-xml')
ESM-only since v3; does not support CommonJS.
minifyStream
import { minifyStream } from 'minify-xml'
import { minifyStream } from 'minify-xml/stream'
Stream transform for large files. No subpath export.
minifyPipeline
import { minifyPipeline } from 'minify-xml'
Promise-based pipeline using stream/promises. Available in v4+.

Basic usage: import default function, pass XML string, get minified XML with removed comments and collapsed whitespace.

import minifyXML from 'minify-xml'; const xml = `<?xml version="1.0"?> <root> <!-- comment --> <child attr1="val1" attr2="val2" /> </root>`; const result = minifyXML(xml); console.log(result); // Output: <?xml version="1.0"?><root><child attr1="val1" attr2="val2"/></root>
Debug
Known issues
gotchaThe `considerPreserveWhitespace` option defaults to true, preserving whitespace in elements with `xml:preserve` attribute. If you want aggressive minification ignoring this, set to false.
fix
Set `considerPreserveWhitespace: false` in options to minify even preserved whitespace elements.
affects: >=1.0.0
gotchaThe `removeWhitespaceBetweenTags` option defaults to true, but if set to `"strict"` only removes whitespace between tags, not between other constructs (e.g., CDATA, comments). Default behavior also removes whitespace around comments, CDATA, etc.
fix
Use `"strict"` to limit removal to tags only, if needed.
affects: >=1.0.0
gotchaNamespace shortening always occurs by default. Unused namespaces are removed; used ones get the shortest unique prefix. This can break XML that relies on specific namespace prefixes.
fix
Set `removeUnusedNamespaces: false` to disable namespace manipulation.
affects: >=1.0.0
breakingv3 dropped CommonJS support. The package is ESM-only, requiring Node.js >=16 and `"type": "module"` or `.mjs` extension.
fix
Update to ESM imports: use `import` instead of `require()`.
affects: >=3.0.0
gotchaCommand-line global install (`npm install -g minify-xml`) provides `minify-xml` CLI, but options are limited. For advanced options, use programmatic API.
fix
Use programmatic import with options object for full control.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'minify-xml'
Using CommonJS `require('minify-xml')` in Node.js <16 or without ESM enabled.
fix
Switch to `import minifyXML from 'minify-xml'` and ensure `"type": "module"` in package.json, or upgrade to Node.js >=16.
TypeError: minifyXML is not a function
Using named import `{ minifyXML }` when the default export is a function. Named import `{ minify }` exists but `minifyXML` is the default.
fix
Use `import minifyXML from 'minify-xml'` (default) or `import { minify } from 'minify-xml'`.
ReferenceError: exports is not defined in ES module scope
Attempting to use CommonJS syntax (`module.exports`) in an ESM context.
fix
Ensure all files use ES module syntax (`import`/`export`).
Upgrade
Version history
4.5.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources