You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
🐛 [BUG] - TypeError: axios.defaults is undefined in v 1.1.0 #5044
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 undefinedthis.projects(project=>{axios({url: `api/Project/${project.value}`,method: 'get',}).then(res=>{// Do something}).catch(err=>{console.log(err.response);})})}
Reacted by Nathan Thomas, Tomas Senk, Simon Robichaud-Paré, takumi, Greg Leuch, 0xLoong, Anthony Luzquiños, Dipansh Parmar and Cromywell
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[/+]on Oct 7, 2022
Reacted by chrisskalog, Muhamad Ristiyanto, Kerry Hormann, Faical, Greg Leuch, alexbujenita, Joris Medeišis, d95mk, arash-bizcover, Anthony Luzquiños and 1 more
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.
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
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.
Activity
[-]🐛 [BUG] - TypeError: axios.defaults is undefined in v 1.0.0 +[/-][+]🐛 [BUG] - TypeError: axios.defaults is undefined in v 1.1.0[/+]zaq42 commentedon 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
zaq42 commentedon 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
requireline below:pie7 commentedon Oct 7, 2022
Probably?
axios/dist/node/axios.cjs
Line 3760 in 9c3dce3
We downgrade to @1.0.0. and it seems fine.
zaq42 commentedon Oct 7, 2022
I think it's this commit: 819ad75
demosjarco commentedon Oct 7, 2022
Issue still persists even with release 1.1.2
rraja6195 commentedon Oct 7, 2022
axios.defaults.headers.common ,
facing the same issue: TypeError: Cannot read properties of undefined (reading 'defaults')
zaq42 commentedon Oct 8, 2022
Fixed for me in 1.1.2.
bakif commentedon Oct 8, 2022
Still facing the same issue with the 1.1.2 release.
gleuch commentedon Oct 8, 2022
For those following the CommonJS change suggested in README by adding
.defaultin require, reverting back toconst axios = require('axios');(removing.default) works for v1.1.2.the-csaba commentedon Oct 10, 2022
It works, withouth TypeScript typings
felix-berlin commentedon Oct 11, 2022
It works with
axios = require('axios').default;🎉wayoalamos commentedon Oct 14, 2022
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 commentedon Oct 22, 2022
Seriously... I've been fighting with this for 3 hours thinking I was messing up something
alexandru96d commentedon Oct 25, 2022
Any fix for this until the new version is released?
donuty commentedon 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.