Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
documentify
✓ const documentify = require('documentify')
✗ import documentify from 'documentify'
Primary CommonJS export for creating a bundler instance. Direct ESM imports may not work without a CommonJS interop layer.
through2
✓ const through = require('through2')
✗ import through from 'through2'
CommonJS import typically used within custom transform modules for stream manipulation, as transforms are based on `through2`.
Demonstrates how to bundle an HTML file with a custom `through2`-based transform to modify its content and log the result.
const { writeFileSync, unlinkSync } = require('fs');
const { join } = require('path');
const documentify = require('documentify');
const through = require('through2'); // Used by transforms
// 1. Create a simple HTML file
const htmlContent = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Original Document</title>
</head>
<body>
<h1>Hello, documentify!</h1>
<p>This is some original content.</p>
</body>
</html>
`;
const entryFilePath = join(__dirname, 'index.html');
writeFileSync(entryFilePath, htmlContent.trim());
// 2. Define a custom transform
function myCustomTransform(opts) {
let buffer = '';
return through(
function (chunk, enc, cb) {
buffer += chunk.toString();
cb();
},
function (cb) {
// Modify the HTML content: add a footer
const modifiedHtml = buffer.replace('</body>', '<footer>Processed by documentify!</footer></body>');
this.push(modifiedHtml);
cb();
}
);
}
// 3. Run documentify
const bundler = documentify(entryFilePath);
// Add the custom transform
bundler.transform(myCustomTransform);
// Bundle and get the output as a readable stream
const bundledStream = bundler.bundle();
let outputHtml = '';
bundledStream.on('data', (chunk) => {
outputHtml += chunk.toString();
});
bundledStream.on('end', () => {
console.log('--- Bundled HTML Output ---');
console.log(outputHtml);
console.log('--- End Output ---');
// Clean up the created file
unlinkSync(entryFilePath);
});
bundledStream.on('error', (err) => {
console.error('Bundling error:', err);
unlinkSync(entryFilePath);
});
documentify --version
Errors
Common errors & fixes
TypeError: documentify is not a function
Trying to use ES module default import syntax (`import documentify from 'documentify'`) without proper Babel/TypeScript configuration or when the package is strictly CommonJS in a Node.js ESM context.
fixUse CommonJS require syntax: `const documentify = require('documentify');` Error: Cannot find module 'through2'
A custom transform requires `through2` but it's not installed as a dependency in the project where the transform is being used.
fixInstall `through2` in your project: `npm install through2`
Error: read ECONNRESET / EPIPE
This error often occurs when `documentify` is used in a pipeline where a downstream process closes its input before `documentify` has finished writing, or when an upstream process (like `cat index.html`) completes prematurely.
fixEnsure all parts of your stream pipeline are correctly handling backpressure and completing gracefully. Check the integrity of input files and the robustness of any custom transforms.
Audit
Dependencies
through2requiredRequired for creating custom transforms that modify the HTML stream, as transforms are expected to return a 'through' stream.