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.
XMLHttpRequest
✓ import { XMLHttpRequest } from 'w3c-xmlhttprequest';
✗ const XMLHttpRequest = require('w3c-xmlhttprequest');
For CommonJS, use destructuring: `const { XMLHttpRequest } = require('w3c-xmlhttprequest');`. Versions 3.0.0-3.0.3 had a regression with `require` support, fixed in v3.0.4.
XMLHttpRequest (Type)
✓ import type { XMLHttpRequest } from 'w3c-xmlhttprequest';
TypeScript types are included and available for explicit import.
NodeXMLHttpRequest
✓ import { XMLHttpRequest as NodeXMLHttpRequest } from 'w3c-xmlhttprequest';
Often aliased to avoid conflict with global browser XMLHttpRequest types in mixed environments.
Demonstrates a basic asynchronous GET request to 'https://example.com/', logging the HTTP status and response details upon completion, including error handling.
import { XMLHttpRequest } from 'w3c-xmlhttprequest';
// This example demonstrates a basic GET request using the server-side XMLHttpRequest.
// It fetches content from a public URL and logs a confirmation message upon successful load.
// Note that network requests in Node.js are asynchronous and non-blocking.
const client = new XMLHttpRequest();
client.open('GET', 'https://example.com/'); // Specify the HTTP method and the target URL.
client.addEventListener('load', () => {
// The 'load' event fires when the transaction is complete, regardless of success or failure.
// Check client.status for HTTP status codes (e.g., 200 for success).
console.log('Received an HTTP response. Status:', client.status);
if (client.status >= 200 && client.status < 300) {
console.log('Response data length:', client.responseText.length, 'characters.');
} else {
console.error('Request failed with status:', client.status);
}
});
client.addEventListener('error', (event) => {
console.error('Network error occurred:', event);
});
client.send(); // Initiates the request.
console.log('GET request sent to example.com...'); // This will log immediately.
Debug
Known issues
breakingVersion 3.0.0 introduced significant changes to align strictly with the W3C/WHATWG Living Standard for XMLHttpRequest. This included enhanced support for features like `EventListenerObject`, `xhr.responseURL`, and `xhr.withCredentials`. Code relying on pre-v3.0.0 behavior or less strict XHR implementations may require updates.fixReview your XHR usage against the W3C specification, especially event listener registration and property access. Update code to conform to standard XHR behavior.
affects: >=3.0.0
gotchaVersions 3.0.0 through 3.0.3 of `w3c-xmlhttprequest` experienced a regression where `require()`-style CommonJS imports might not have functioned correctly or consistently, leading to errors when attempting to instantiate `XMLHttpRequest`.fixUpgrade to `w3c-xmlhttprequest@3.0.4` or later for full CommonJS compatibility. Alternatively, use ES module `import` syntax if your environment supports it.
affects: >=3.0.0 <3.0.4
gotchaThe package requires Node.js version 10.13.0 or higher. Using it with older Node.js versions will result in installation or runtime failures.fixEnsure your Node.js environment meets the minimum requirement of 10.13.0 or upgrade Node.js.
affects: <10.13.0 Node.js
gotchaWhile `w3c-xmlhttprequest` mimics browser XHR, it operates in a server-side Node.js environment. This means certain browser-specific behaviors, like automatic cookie handling, credential management, or CORS preflight logic (beyond the base HTTP request), are not automatically replicated and might require manual implementation or additional Node.js modules.fixBe mindful of environmental differences. For features like cookie management or complex credential handling, integrate appropriate Node.js HTTP utilities or proxy setups if needed.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: XMLHttpRequest is not a constructor
Attempting to import `XMLHttpRequest` incorrectly using CommonJS `require()` in versions 3.0.0-3.0.3, or an incorrect import path.
fixEnsure your package version is `w3c-xmlhttprequest@3.0.4` or higher for reliable CommonJS. Use destructuring for `require`: `const { XMLHttpRequest } = require('w3c-xmlhttprequest');`. For ESM, use `import { XMLHttpRequest } from 'w3c-xmlhttprequest';`. TypeError: EventTarget.prototype.addEventListener called with a non-object argument
Passing an invalid or non-object argument to the `addEventListener` method, which expects an `EventListener` or `EventListenerObject`.
fixVerify that the argument passed to `addEventListener` is a valid function or an object implementing `handleEvent()`, as per the W3C EventTarget specification. This issue was addressed in beta versions leading to 3.0.0.
Audit
Dependencies
No dependency data recorded yet.