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.
got
✓ const got = require('got-cjs');
✗ import got from 'got-cjs';
This package is explicitly for CommonJS environments. For ESM, use the main 'got' package directly.
got
✓ const got = require('got-cjs');
const { URLSearchParams } = require('url'); // Example for a common Node.js global
✗ import { got } from 'got-cjs';
The primary export is a default `got` instance; named exports are not typical for this CJS wrapper.
GotReturn
✓ import type { GotReturn } from 'got-cjs';
✗ type GotReturn = ReturnType<typeof require('got-cjs')>;
TypeScript types are provided and should be imported using standard ESM `import type` syntax, even in a CJS project if using TS.
Demonstrates a basic GET request with headers and timeout, followed by a JSON POST request, using the `got-cjs` API.
const got = require('got-cjs');
(async () => {
try {
const response = await got('https://httpbin.org/get', {
headers: {
'User-Agent': 'my-awesome-app/1.0'
},
timeout: {
request: 5000 // 5 seconds
}
});
console.log('Status Code:', response.statusCode);
console.log('Body:', response.body.substring(0, 200) + '...');
const postResponse = await got.post('https://httpbin.org/post', {
json: {
hello: 'world'
},
responseType: 'json'
});
console.log('Posted JSON:', postResponse.body);
} catch (error) {
console.error('Request failed:', error.message);
}
})();
Debug
Known issues
breakingThe primary `got` package (v12 and newer) is pure ESM and cannot be directly `require()`d. `got-cjs` specifically provides a CommonJS wrapper for `got` v11, which means it will not receive new features or API changes from `got` v12+.fixFor CommonJS projects, continue using `got-cjs`. For new projects or existing projects able to migrate, consider migrating to ESM and using `got` v12+ directly via `import` statements.
affects: >=12.0.0 (for `got` itself)
gotcha`got-cjs` bundles `got` v11.8.3. This means that any new features, performance improvements, or non-security bug fixes introduced in `got` v12 or later will not be available when using `got-cjs`. Only security patches for `got` v11 will likely be backported.fixReview the changelogs for the main `got` package. If crucial new features or fixes are needed, migrating your project to ESM to use `got` v12+ is recommended.
affects: >=1.0.0
gotchaWhile `got-cjs` enables CommonJS usage, the Node.js ecosystem is increasingly standardizing on ECMAScript Modules (ESM). Relying heavily on CJS wrappers might limit access to newer libraries or features in the long term.fixEvaluate your project's module system. If feasible, migrate to ESM to leverage the broader modern JavaScript ecosystem and directly use `got` v12+.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: Must use import to load ES Module: .../node_modules/got/dist/source/index.js
Attempting to `require('got')` (the main `got` package) in a CommonJS environment when `got` version 12 or newer is installed.
fixInstall `got-cjs` and change your import to `const got = require('got-cjs');`. TypeError: got is not a function
This error can occur if you mistakenly try to use `require('got')` with `got` v12+ in a CJS file and then try to call it. While the `require` might partially work for an ESM module, the default export is not directly callable as a function in the CJS `require` context without specific interop.
fixIf your project is CommonJS, use `const got = require('got-cjs');`. If your project is ESM, use `import got from 'got';`. Audit
Dependencies
gotrequiredCore HTTP client functionality, `got-cjs` wraps `got` v11.