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)

Most upvoted comments

Issue still persists even with release 1.1.2

(removing .default) works for v1.1.2.

It works, withouth TypeScript typings

For those following the CommonJS change suggested in README by adding .default in require, reverting back to const axios = require('axios'); (removing .default) works for v1.1.2.

Still facing the same issue with the 1.1.2 release.