Migrate from v1.0.x to v2.0.0
mainUpgrading from v1.x to v2.x involves several breaking changes regarding requirements, exports, and configuration usage.
Update requirements
- Node.js: v12.19.0 / v14.5.0 or above
- axios: @0.20.0 or above
- tough-cookie: @4.0.0 or above
Wrapper function is now a named export
The wrapper function is no longer the default export. You must use named exports.
config.withCredentials is no longer used
Do not use withCredentials to manage cookie behavior.
- To prevent sending cookies, unset
config.jardirectly. - To allow cookies, provide a
CookieJarinstance toconfig.jar.
config.httpAgent and config.httpsAgent compatibility
You cannot use config.httpAgent or config.httpsAgent directly with axios-cookiejar-support. Instead, use http-cookie-agent to allow using other Agents (like Proxy Agents) with a CookieJar.
config.jar no longer accepts boolean
Passing true to config.jar is no longer supported. You must pass an actual CookieJar instance.
Invalid cookies are ignored
Since v2.0, invalid cookies are always ignored instead of throwing an error. The ignoreCookieErrors: true option is no longer necessary.
// CommonJS
- const axiosCookieJarSupport = require('axios-cookiejar-support');
+ const { wrapper: axiosCookieJarSupport } = require('axios-cookiejar-support'); // ES Module
- import axiosCookieJarSupport from 'axios-cookiejar-support';
+ import { wrapper as axiosCookieJarSupport } from 'axios-cookiejar-support'; // Remove config.withCredentials
axios.get('https://example.com', {
jar: new CookieJar(),
- withCredentials: true,
}); // Remove config.jar for preventing to send cookie
axios.get('https://example.com', {
- jar: new CookieJar(),
- withCredentials: false,
});import axios from 'axios';
import { CookieJar } from 'tough-cookie';
import { createCookieAgent } from 'http-cookie-agent';
import httpProxyAgent from 'http-proxy-agent';
import httpsProxyAgent from 'https-proxy-agent';
const HttpProxyCookieAgent = createCookieAgent(httpProxyAgent.HttpProxyAgent);
const HttpsProxyCookieAgent = createCookieAgent(httpsProxyAgent.HttpsProxyAgent);
const jar = new CookieJar();
const client = axios.create({
httpAgent: new HttpProxyCookieAgent({ jar, hostname: '127.0.0.1', port: 8080 }),
httpsAgent: new HttpsProxyCookieAgent({ jar, hostname: '127.0.0.1', port: 8080 }),
});
await client.get('https://example.com'); // Cannot use boolean as config.jar since v2.x
+ const cookieJar = new CookieJar();
axios.get('https://example.com', {
- jar: true,
+ jar: cookieJar,
}); const cookieJar = new CookieJar();
axios.get('https://example.com', {
jar: cookieJar,
- ignoreCookieErrors: true,
});