{"id":26971,"library":"extrareqp2","title":"Axios","description":"Axios is a promise-based HTTP client for both browser and Node.js. The current stable version is 1.0.0. It provides a simple API for making XMLHttpRequests in the browser and http requests in Node.js, with features like interceptors, automatic JSON transformation, and request cancellation. Axios is widely used due to its ease of use, support for older browsers (IE11), and TypeScript types. It follows semver and has a consistent release cadence with minor updates every few months.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/keymetrics/extrareqp2","tags":["javascript","xhr","http","ajax","promise","node","typescript"],"install":[{"cmd":"npm install extrareqp2","lang":"bash","label":"npm"},{"cmd":"yarn add extrareqp2","lang":"bash","label":"yarn"},{"cmd":"pnpm add extrareqp2","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default import. Axios is ESM-compatible since v1; CommonJS require still works in Node.","wrong":"const axios = require('axios')","symbol":"axios","correct":"import axios from 'axios'"},{"note":"Type-only import for TypeScript users. Available in v1+.","wrong":"const { AxiosInstance } = require('axios')","symbol":"AxiosInstance","correct":"import axios, { AxiosInstance } from 'axios'"},{"note":"Type only, used for custom configs. Cannot be value-imported via require.","wrong":"const { AxiosRequestConfig } = require('axios')","symbol":"AxiosRequestConfig","correct":"import axios, { AxiosRequestConfig } from 'axios'"},{"note":"Correct symbol is AxiosResponse, not 'response'. TypeScript type.","wrong":"import { response } from 'axios'","symbol":"AxiosResponse","correct":"import { AxiosResponse } from 'axios'"}],"quickstart":{"code":"import axios from 'axios';\n\nasync function main() {\n  try {\n    const response = await axios.get('https://api.example.com/data', {\n      params: { key: process.env.API_KEY ?? '' },\n      timeout: 5000\n    });\n    console.log(response.data);\n  } catch (error) {\n    if (axios.isAxiosError(error)) {\n      console.error('Axios error:', error.message);\n    } else {\n      console.error('Unexpected error:', error);\n    }\n  }\n}\n\nmain();","lang":"typescript","description":"Shows a GET request with params, error handling with axios.isAxiosError, and async/await usage."},"warnings":[{"fix":"Use import axios from 'axios' instead of require('axios'). In TypeScript, use esModuleInterop.","message":"Starting from v0.22.0, Axios supports ES modules and has changed default export behavior.","severity":"breaking","affected_versions":">=0.22.0"},{"fix":"Use `httpAdapter` for Node.js or `xhrAdapter` for browser instead of `adapter`.","message":"The `adapter` config option is deprecated in favor of `httpAdapter` and `xhrAdapter`.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Set `responseType: 'text'` explicitly if expecting non-JSON responses, or use `transformResponse`.","message":"Axios v1 changed the default response type from `text` to `json` for all requests, including those that return non-JSON content.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Refer to axios documentation for compatibility; extrareqp2 may have unknown breaking changes.","message":"Initial release of extrareqp2 is a fork of axios v1.0.0? Check version history.","severity":"breaking","affected_versions":"1.0.0"},{"fix":"Use AbortController from the platform (browser or Node.js 16+) to cancel requests.","message":"The `CancelToken` API is deprecated; use `AbortController` instead.","severity":"deprecated","affected_versions":">=0.22.0"},{"fix":"For JSON, ensure data is an object and Axios will set Content-Type: application/json automatically. For form data, use URLSearchParams or FormData.","message":"axios.post(url, data, config) does NOT automatically stringify data; set `Content-Type` header manually if needed.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Check if error.response exists before accessing data: if (error.response) { console.log(error.response.data); }","cause":"Trying to access response.data when request failed and error.response is undefined.","error":"TypeError: Cannot read properties of undefined (reading 'data')"},{"fix":"Run `npm install axios` and ensure the import path is correct. For CDN, use script tag.","cause":"Axios is not installed or incorrectly imported in a browser environment.","error":"Module not found: Error: Can't resolve 'axios'"},{"fix":"Check browser console for CORS errors, ensure endpoint is reachable, and configure CORS on server.","cause":"Request failed due to network issues (e.g., CORS, no internet, blocked request).","error":"Uncaught (in promise) Error: Network Error"},{"fix":"Use `const axios = require('axios')` in Node.js CJS or enable esModuleInterop in tsconfig.","cause":"Using import axios from 'axios' in a CommonJS module without esModuleInterop.","error":"TypeError: _axios.default.get is not a function (or axios.get is not a function)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}