Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 [BUG] - TypeError: axios.defaults is undefined in v 1.1.0 #5044

Closed
anthea-wu opened this issue Oct 7, 2022 · 15 comments 路 Fixed by #5162
Closed

馃悰 [BUG] - TypeError: axios.defaults is undefined in v 1.1.0 #5044

anthea-wu opened this issue Oct 7, 2022 · 15 comments 路 Fixed by #5162

Comments

@anthea-wu
Copy link

anthea-wu commented Oct 7, 2022

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);
        })
    })
}
@anthea-wu anthea-wu changed the title 馃悰 [BUG] - TypeError: axios.defaults is undefined in v 1.0.0 + 馃悰 [BUG] - TypeError: axios.defaults is undefined in v 1.1.0 Oct 7, 2022
@zaq42
Copy link

zaq42 commented Oct 7, 2022

Same here. 1.0.0 didn't have this problem, but #4999 was a show stopper for us.

In 1.1.0, I think this another problem introduced by #5030

% yarn node
Welcome to Node.js v16.17.0.
Type ".help" for more information.
> const axios = require('axios')
undefined
> axios.defaults.baseURL = "https://www.google.com"
Uncaught TypeError: Cannot set properties of undefined (setting 'baseURL')

@zaq42
Copy link

zaq42 commented Oct 7, 2022

It looks like the default is no longer the default. As a workaround, you can explicitly use it; note the change in the require line below:

% yarn node
Welcome to Node.js v16.17.0.
Type ".help" for more information.
> const axios = require('axios').default
undefined
> axios.defaults.baseURL = "https://www.google.com"
'https://www.google.com'

@pie7
Copy link

pie7 commented Oct 7, 2022

Probably?

exports["default"] = axios;

We downgrade to @1.0.0. and it seems fine.

@zaq42
Copy link

zaq42 commented Oct 7, 2022

I think it's this commit: 819ad75

image

@demosjarco
Copy link

Issue still persists even with release 1.1.2

@rraja6195
Copy link

axios.defaults.headers.common ,
facing the same issue: TypeError: Cannot read properties of undefined (reading 'defaults')

@zaq42
Copy link

zaq42 commented Oct 8, 2022

Fixed for me in 1.1.2.

@bakif
Copy link

bakif commented Oct 8, 2022

Still facing the same issue with the 1.1.2 release.

@gleuch
Copy link

gleuch commented Oct 8, 2022

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.

@om4csaba
Copy link
Contributor

(removing .default) works for v1.1.2.

It works, withouth TypeScript typings

@felix-berlin
Copy link

It works with axios = require('axios').default; 馃帀

@wayoalamos
Copy link

This problem persist for me. For some reason, when compiling typescript to javascript, it adds a "default" after axios... and terminal is complaining that axios.default is undefined.
Example:
In index.ts I have: axios.request("my api")
When compiling I see in index.js:
axios.default.request("my api") and this fails with error : TypeError: Cannot read property 'request' of undefined

@fgatti675
Copy link

Seriously... I've been fighting with this for 3 hours thinking I was messing up something

@alexandru96d
Copy link

Any fix for this until the new version is released?

@donuty
Copy link

donuty commented Oct 29, 2022

Not an ideal way to fix this but after compiling, remove ['default'] from where it's on any axios request and the compiled ['default']-free file will run properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.