Registry / devops / x-fetch

x-fetch

JSON →
library0.2.6jsnpmunverified

An ultra-lightweight wrapper around the native fetch API (<880B minified + brotlied) that provides a convenient, isomorphic interface for HTTP requests. Currently at version 0.2.6 (early development), it follows semver but expect frequent changes. Key differentiators: tiny size, built-in TypeScript types, interceptor support (similar to axios), automatic JSON serialization for object bodies, and URL query parameter handling. Released under the UnTS organization with conventional commits and changesets.

npm install x-fetch
INSTALL
IMPORT
SIG · X-FETCH
X
x-fetch
devopsjavascriptv0.2.6
harness data pending
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.

xfetch
import { xfetch } from 'x-fetch'
const xfetch = require('x-fetch')
ESM only; CJS require will fail as the package only exports ESM.
createXFetch
import { createXFetch } from 'x-fetch'
import createXFetch from 'x-fetch'
createXFetch is a named export, not default.
interceptors
import { interceptors } from 'x-fetch'
Global interceptors singleton. For isolated instances, use createXFetch().
ApiMethod
import { ApiMethod } from 'x-fetch'
Enum-like object with HTTP method constants.
ApiInterceptor
import type { ApiInterceptor } from 'x-fetch'
TypeScript only; use import type.

Demonstrates basic GET and POST usage with query parameters and automatic JSON serialization.

import { xfetch } from 'x-fetch' async function main() { // GET request const data = await xfetch('https://api.example.com/data') console.log(data) // POST with JSON body and query params const result = await xfetch('https://api.example.com/submit', { method: 'POST', body: { key: 'value' }, query: { token: process.env.API_TOKEN ?? '' }, }) console.log(result) } main().catch(console.error)
Debug
Known issues
gotchaPackage is version 0.2.6; APIs may change without major version bump.
fix
Pin exact version and test upgrades.
affects: <1.0.0
gotchaESM-only package; CommonJS require() will throw an error.
fix
Use import syntax or dynamic import() in CJS projects.
affects: >=0.1.0
gotchaRequires Node.js >=14.0.0 and a native fetch implementation (e.g., undici via Node 18+). Older Node versions may need polyfill.
fix
Upgrade Node to 18+ or install node-fetch and polyfill global fetch.
affects: >=0.1.0
gotchaThe interceptor list is global by default; mutations affect all requests. For isolation, use createXFetch().
fix
Use createXFetch() to create separate interceptor chains per context.
affects: >=0.1.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module
Using require() instead of import on an ESM-only package.
fix
Change to import { xfetch } from 'x-fetch' or use dynamic import() if in CJS context.
TypeError: fetch is not defined
Node.js version < 18 or environment lacks native fetch (e.g., older Node, some bundlers).
fix
Use Node >= 18 or install a fetch polyfill like 'undici' and assign global.fetch.
Cannot find module 'x-fetch' or its corresponding type declarations.
TypeScript is not configured to resolve node modules or missing typeRoots.
fix
Ensure 'moduleResolution' is 'node' or 'node16' in tsconfig.json. The package includes types.
Upgrade
Version history
0.2.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
Resources
x-fetch — npm install x-fetch · libregistry