Install & Compatibility
Where this runs
tested against v1.20.0 · 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
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
axios
✓ import axios from 'axios';
✗ import { axios } from 'axios'; // Incorrect for default export
const axios = require('axios'); // CommonJS import pattern
Axios exports its main functionality as a default export. For CommonJS environments, `require('axios')` is the correct approach.
AxiosRequestConfig, AxiosResponse, AxiosError
✓ import type { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios';
✗ import { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios'; // Imports types as values, can cause issues or larger bundles
When importing only types, use `import type` to ensure they are stripped during compilation, preventing accidental runtime imports and optimizing bundle size, especially in TypeScript projects.
axios.create
✓ import axios from 'axios';
const instance = axios.create({ baseURL: 'https://api.example.com' });
✗ import { create } from 'axios'; // `create` is a method of the default `axios` export, not a named export.
Custom Axios instances, which allow for distinct configurations (e.g., different `baseURL`, headers), are created by calling the `create` method on the default `axios` export.
This quickstart demonstrates a basic GET request to a public API, including asynchronous execution and robust error handling to differentiate between Axios-specific errors and general JavaScript errors.
import axios from 'axios';
async function fetchData() {
try {
const response = await axios.get('https://jsonplaceholder.typicode.com/todos/1');
console.log(response.data);
} catch (error) {
if (axios.isAxiosError(error)) {
console.error('Axios error:', error.message);
console.error('Status:', error.response?.status);
} else {
console.error('Unexpected error:', error);
}
}
}
fetchData();
Debug
Known issues
breakingAxios versions prior to v1.0.0 (and v0.31.0 for the v0.x branch) were vulnerable to Header Injection and Proxy Bypass. This was due to insufficient sanitization of outgoing header values and improper `NO_PROXY`/`no_proxy` enforcement.fixUpgrade to Axios v1.0.0+ or v0.31.0+ immediately to apply security hardening, which sanitizes header values and correctly enforces `NO_PROXY`.
affects: <1.0.0, <0.31.0
breakingA Denial of Service (DoS) vulnerability (prototype pollution) could occur when processing specifically crafted configuration objects utilizing the `__proto__` key in `mergeConfig`.fixUpgrade to Axios v1.13.5+ or v0.30.3+ to patch this vulnerability and prevent potential DoS attacks.
affects: <1.13.5, <0.30.3
deprecatedAxios previously used Node.js's deprecated `url.parse()` internally, which could lead to console warnings in recent Node.js environments.fixUpgrade to Axios v1.15.0+ to resolve Node.js deprecation warnings related to `url.parse()` usage.
affects: <1.15.0
breakingVersion 1.14.0 introduced `proxy-from-env` v2 alignment and `main` entry compatibility fixes. Users relying on environment-based proxy behavior or specific CommonJS resolution edge cases should validate their integration.fixThoroughly test your application's proxy configurations and CommonJS module resolution after upgrading to v1.14.0 or later to ensure continued compatibility.
affects: >=1.14.0
gotchaA bug existed in versions 1.13.3 and 1.13.4 where the `AxiosError` object could intermittently be missing the `status` field, impacting error handling logic that relies on this property.fixUpgrade to Axios v1.13.5+ to ensure the `status` field is reliably present on `AxiosError` objects.
affects: 1.13.3 - 1.13.4
gotchaPrior to v1.13.2, applications using `keep-alive` requests with timeouts in Node.js could experience 'socket hang up' errors.fixUpgrade to Axios v1.13.2+ to fix the 'socket hang up' bug for keep-alive requests when using timeouts.
affects: <1.13.2
gotchaA regression in versions prior to v1.13.1 caused the data stream to be interrupted for responses with non-OK HTTP statuses, preventing full response body retrieval.fixUpgrade to Axios v1.13.1+ to resolve the regression and ensure complete data stream reception for responses with any HTTP status.
affects: <1.13.1
Errors
Common errors & fixes
TypeError: axios is not a function
This typically occurs when `axios` is incorrectly imported as a named export (`import { axios } from 'axios';`) or when a CommonJS `require()` statement is used in an ES module context without proper setup.
fixFor ES Modules, use `import axios from 'axios';`. For CommonJS, use `const axios = require('axios');`. TypeError: Cannot read properties of undefined (reading 'status')
Attempting to access `error.response.status` when `error.response` is undefined. This happens if the error is not an HTTP response error (e.g., network error, request timeout, or a JavaScript error), meaning no `response` object was generated.
fixAlways check `if (axios.isAxiosError(error) && error.response)` before trying to access `error.response` properties. For network errors without a response, `error.code` (e.g., 'ECONNABORTED', 'ERR_NETWORK') can be useful.
Network Error (browser) / Error: connect ECONNREFUSED (Node.js)
The request failed to reach the server. This could be due to the server being offline, an incorrect URL, lack of internet connectivity, firewall issues, or a browser-specific CORS policy blocking the request.
fixVerify the target URL is correct and accessible. Check the server's status, your internet connection, and any local firewall settings. In a browser, inspect the console for CORS-related error messages.
AxiosError: Request failed with status code 401
The server received the request but rejected it due to authentication issues, typically meaning missing, invalid, or expired credentials.
fixEnsure your request includes the correct and current authentication credentials (e.g., API key, JWT bearer token) in the headers or body as required by the API you are calling.
Audit
Dependencies
No dependency data recorded yet.