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.
meros
✓ import { meros } from 'meros';
✗ import meros from 'meros';
Meros exclusively uses named exports. The main 'meros' import relies on bundler or environment detection to serve the correct version. For explicit control and potential optimizations, consider using environment-specific subpath imports (`meros/browser` or `meros/node`).
meros (Browser)
✓ import { meros } from 'meros/browser';
✗ import { meros } from 'meros';
This import explicitly targets browser environments. It's recommended when building for the web to ensure correct module resolution and take advantage of any browser-specific optimizations or tree-shaking by bundlers.
meros (Node.js)
✓ import { meros } from 'meros/node';
✗ const { meros } = require('meros/node');
This import explicitly targets Node.js environments (requires `node >=13`). It's recommended for server-side applications to ensure correct module resolution and access to Node.js-specific streaming interfaces. The package is designed for ESM usage.
Demonstrates fetching a response, processing it with `meros`, and gracefully handling both `multipart/mixed` and non-multipart (e.g., JSON) responses using an async generator pattern.
import { meros } from 'meros';
async function fetchAndProcessMultipart() {
// Simulate a multipart/mixed response or a regular JSON response
// In a real application, replace with your actual fetch call
const mockFetch = async (url: string) => {
if (url === '/api/multipart') {
// Example multipart response
return new Response(
`--boundary\r\nContent-Type: application/json\r\n\r\n{"data": "part1"}\r\n--boundary\r\nContent-Type: text/plain\r\n\r\nhello from part 2\r\n--boundary--`,
{
headers: { 'Content-Type': 'multipart/mixed; boundary=boundary' }
}
);
} else {
// Example non-multipart JSON response
return new Response(JSON.stringify({ message: 'Not multipart' }), {
headers: { 'Content-Type': 'application/json' }
});
}
};
try {
const response = await mockFetch('/api/multipart'); // Try with '/api/json' to see the other path
const parts = await meros(response);
if (parts && typeof (parts as any)[Symbol.asyncIterator] === 'function') {
console.log('Processing multipart response:');
for await (const part of parts) {
if (part.json) {
console.log(' JSON Part:', part.body);
} else {
console.log(' Text/Other Part:', new TextDecoder().decode(part.body as Uint8Array));
}
}
} else {
console.log('Not a multipart response, processing as regular response:');
const data = await (parts as Response).json();
console.log(' Response Data:', data);
}
} catch (error) {
console.error('Error fetching or processing:', error);
}
}
fetchAndProcessMultipart();
Errors
Common errors & fixes
TypeError: parts is not async iterable
This error occurs when attempting to use `for await (const part of parts)` on the value returned by `meros` when the HTTP response's `Content-Type` header was not `multipart/mixed`. In such cases, `meros` returns the original `Response` object, which is not an async iterable.
fixBefore iterating, always check if the returned `parts` object is an async iterable using `if (parts && typeof (parts as any)[Symbol.asyncIterator] === 'function')`. If not, process `parts` as a standard `Response` object (e.g., `parts.json()`).
ReferenceError: require is not defined
Attempting to use `require('meros')` or `require('meros/node')` in an environment that expects ECMAScript Modules (ESM) syntax, such as a modern Node.js project or a browser module without proper CommonJS transpilation.
fixMeros is primarily designed for ESM. Update your import statements to use `import { meros } from 'meros';` (or specific subpath imports) and ensure your project's `package.json` specifies `"type": "module"` or your build setup correctly handles ESM. Audit
Dependencies
@types/noderequiredProvides type definitions for Node.js environments when using TypeScript; a peer dependency for proper type checking.