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.
captureFetchGlobal
✓ const { captureFetchGlobal } = require('aws-xray-sdk-fetch');
✗ import { captureFetchGlobal } from 'aws-xray-sdk-fetch';
Package is CJS-only; ESM imports cause runtime error.
captureFetchModule
✓ const { captureFetchModule } = require('aws-xray-sdk-fetch');
✗ import captureFetchModule from 'aws-xray-sdk-fetch';
CJS-only export; also the first argument to captureFetchModule must be the node-fetch module, not a reference to fetch function.
types
✓ import type { CaptureFetchGlobal, CaptureFetchModule } from 'aws-xray-sdk-fetch';
✗ import { CaptureFetchGlobal } from 'aws-xray-sdk-fetch';
Use type-only imports for TypeScript types to avoid runtime side effects.
AWSXRay
✓ const AWSXRay = require('aws-xray-sdk-core');
✗ const AWSXRay = require('aws-xray-sdk-fetch');
The core SDK is a separate package; fetch plugin only provides capture functions.
Shows how to initialize AWSXRay with manual mode and instrument global fetch using captureFetchGlobal.
const AWSXRay = require('aws-xray-sdk-core');
const { captureFetchGlobal } = require('aws-xray-sdk-fetch');
// Enable AWSXRay (e.g., with manual mode)
AWSXRay.enableManualMode();
// Use global fetch (Node.js 18+)
const fetch = captureFetchGlobal();
async function makeRequest() {
const result = await fetch('https://api.example.com/data');
const data = await result.json();
console.log(data);
}
makeRequest();
Errors
Common errors & fixes
TypeError: fetch is not a function
captureFetchGlobal() returns undefined if global fetch is not available (Node <18).
fixUse captureFetchModule with node-fetch v2 instead, or upgrade Node.
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Trying to require node-fetch v3 which is ESM-only.
fixInstall node-fetch v2: npm install node-fetch@2
Cannot find module 'aws-xray-sdk-core'
Missing peer dependency aws-xray-sdk-core.
fixInstall it: npm install aws-xray-sdk-core
TypeError: segment is not a segment
AWSXRay not properly initialized before calling captureFetchGlobal/Module.
fixEnsure AWSXRay.enableManualMode() or other initialization is called first.
SyntaxError: Cannot use import statement outside a module
Using ESM import syntax in a CommonJS file.
fixSwitch to require() or use .mjs extension with ESM imports (but package is CJS-only).
Audit
Dependencies
aws-xray-sdk-corerequiredpeer dependency; provides core segment/subsegment creation and context management
node-fetchoptionaloptional; required only when using captureFetchModule with node-fetch v2