Registry / testing / fetch-cookie

fetch-cookie

JSON →
library3.2.0jsnpmunverified

A decorator for fetch functions (both native and polyfill like node-fetch) to support automatic cookie storage and sending. v3.2.0 is stable, with frequent updates. Key differentiator: simple wrapper API, supports custom tough-cookie jar, and works with any fetch-compatible library. Ships TypeScript definitions. Heavily depends on tough-cookie for cookie management.

npm install fetch-cookie
INSTALL
IMPORT
SIG · FETCH-COOKIE
F
fetch-cookie
testingjavascriptv3.2.0
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.

default
import makeFetchCookie from 'fetch-cookie'
const makeFetchCookie = require('fetch-cookie')
ESM default export since v3; CommonJS require() fails. Use dynamic import or ensure ESM.
fetchCookie (named)
import { default as fetchCookie } from 'fetch-cookie'
import { fetchCookie } from 'fetch-cookie'
No named export 'fetchCookie'; use default import with alias.
toughCookie
import makeFetchCookie from 'fetch-cookie'; const ToughCookie = makeFetchCookie.toughCookie
import { toughCookie } from 'fetch-cookie'
toughCookie is attached as a static property on the default export, not a named export.

Shows basic usage: create fetch wrapper, make requests that automatically handle cookies.

import makeFetchCookie from 'fetch-cookie'; // Using native fetch (Node 18+) const fetchCookie = makeFetchCookie(fetch); async function example() { const response = await fetchCookie('https://httpbin.org/cookies/set?name=value'); console.log(await response.text()); // Subsequent requests will include the cookie const response2 = await fetchCookie('https://httpbin.org/cookies'); console.log(await response2.text()); } example().catch(console.error);
Debug
Known issues
breakingv3 switched to ESM only. CommonJS require() will throw MODULE_NOT_FOUND.
fix
Use import syntax or dynamic import. Or stick with v2 if CJS required.
affects: >=3.0.0
deprecatedv2 used default export of a function that returned a fetch wrapper. v3 exports a factory function.
fix
Update import to default import and call makeFetchCookie(fetch) instead of fetchCookie(fetch).
affects: >=2.0.0 <3.0.0
gotchatough-cookie is a peer dependency. Must be installed separately.
fix
Run npm install tough-cookie.
affects: >=3.0.0
gotchaWhen using with node-fetch, ensure node-fetch v3 (ESM) is used. v2 (CJS) will cause issues.
fix
Use node-fetch@3 or native fetch.
affects: >=3.0.0
deprecatedv1 exported a function that accepted (fetch, jar?) and returned fetch. v2+ changed signature.
fix
Migrate to v3 import style.
affects: <2.0.0
Errors
Common errors & fixes
Must use import to load ES Module: require() of ES Module not supported.
Using CommonJS require() on ESM-only package.
fix
Change to import or use dynamic import().
ERR_PACKAGE_PATH_NOT_EXPORTED: Package subpath './package.json' is not defined by "exports".
Trying to require a subpath that is not exported.
fix
Use the package's main entry point via import.
TypeError: makeFetchCookie is not a function
Using wrong import (e.g., named import instead of default).
fix
Use import makeFetchCookie from 'fetch-cookie' (default import).
Upgrade
Version history
3.2.0latest on npm
Audit
Dependencies
tough-cookieoptionalCore cookie jar implementation; optional if custom jar provided.
Agent activity
2 hits · last 30 days
node
2
Resources
fetch-cookie — npm install fetch-cookie · libregistry