crowd-sourced migration guide for axios1.0.0
- axios docs
- official migration guide
- axios Community Discussion
- Upgrade Guide needs to be updated with 0.x.x -> 1.0.0
- Is axios@1 stable?
Documenting the potential breaking changes between 0.27.2...1.0.0
- not all have solutions, but are here for completeness
- this guide mentions
1.0.0
, but most likely you will want to go to the latest1.x
version
from @ghiscoding via axios/axios#4996 (comment)
If you were using axios@0.x with ESM/Vite, such as in Vue3, your import syntax may have changed:
- import { axios } from '@bundled-es-modules/axios';
+ import axios from 'axios';
from @ghiscoding via axios/axios#4996 (comment)
the only other issue we had was with the AxiosRequestConfig interface that we use in our http interceptors and for that we simply had to switch to the InternalAxiosRequestConfig interface
- import { axios, AxiosRequestConfig, AxiosResponse } from '@bundled-es-modules/axios';
+ import axios, { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
function startInterceptors() {
axios.interceptors.request.use(onRequestFullfilled, onRequestResponseRejected);
axios.interceptors.response.use(onResponseFullfilled, onRequestResponseRejected);
}
async function onRequestResponseRejected(reason: AxiosError<string>) {
- const originalRequest = reason.config;
+ const originalRequest = reason.config as InternalAxiosRequestConfig;
// ...
}
Look out for the shape of request.headers
to have changed.
- if (request.headers?.common?.Authorization) {
- request.headers.common.Authorization =
+ if (request.headers?.Authorization) {
+ request.headers.Authorization =
axiosInstance.defaults.headers.common.Authorization;
}
internals that may not be exposed anymore