axios: π [BUG] - TypeError: axios.defaults is undefined in v 1.1.0
Description
I use CDN with https://unpkg.com/axios/dist/axios.min.js
without specify version in my project, and before new version release, I can work it well.
But after new version release, it will show the error:
TypeError: axios.defaults is undefined
I tried to find some release notes or upgrade guide but I saw someone find them too, so I rollback to old version, and it works now! But I have several pages needs to rollback the version π’
Is rollback version only way to fix this error?
Code
I used axios with Vue.js, and this is the part in my Vue app:
getProjectSec: function (token) {
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
// ^^^^^ Uncaught (in promise) TypeError: axios.defaults is undefined
this.projects(project => {
axios({
url: `api/Project/${project.value}`,
method: 'get',
}).then(res => {
// Do something
}).catch(err => {
console.log(err.response);
})
})
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 9
- Comments: 15 (1 by maintainers)
Issue still persists even with release 1.1.2
It works, withouth TypeScript typings
For those following the CommonJS change suggested in README by adding
.default
in require, reverting back toconst axios = require('axios');
(removing.default
) works for v1.1.2.Still facing the same issue with the 1.1.2 release.
I think itβs this commit: https://github.com/axios/axios/pull/5030/commits/819ad75564f472a9066fa4de3eaf416604daddc5