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
[1.0.0] TypeError: Cannot read properties of undefined (reading 'create') #5011
const client = axios.create()
^
TypeError: Cannot read properties of undefined (reading 'create')
at Object.<anonymous> (/Users/rob/Developer/Personal/full-feed/test.js:5:22)
at Module._compile (node:internal/modules/cjs/loader:1149:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1203:10)
at Module.load (node:internal/modules/cjs/loader:1027:32)
at Module._load (node:internal/modules/cjs/loader:868:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
Node.js v18.10.0
Reacted by Izabela Furdzik, abhinavdhangar, Tom Ruloff, Dan Page, Ansh Agarwal, Garrett, david690, Vasilis Danias, Jin-Yong Lee, Aryansh Malviya and 5 more
Uncaught TypeError: axios.create is not a function
at eval (api.js:5:1)
My code is - instance:
constaxios=require('axios');const{ gateway }=require('../config/environment');const{ version }=require('../../package.json');constapi=axios.create({baseURL: gateway,headers: {'Content-Type': 'application/json; charset=UTF-8','Cache-Control': 'no-cache',Pragma: 'no-cache','X-Application-Name': 'app-name','X-Application-Version': version}});api.interceptors.response.use((response)=>response.data,(error)=>{throwerror;});module.exports={ api };
And request, for example:
const{ api }=require('../config/api');constgetSomeEndpoint=(data)=>(api.post('endpoint',data));module.exports={ getSomeEndpoint };
I am not sure where is the problem, I can't find it in my code 😞
Yes, this form is functional, but you don't have the helpers either the types. When you use default the method create return undefined, this is the reason of the error.
With .default app is working correctly, but during the build it crashes.
I am using gatsby and during the build I do the first requests.
(I have build app without default, It passed, and then added default and reloaded, then was OK, but still when I try to build once again, the app not built) 😞
gatsby-node.js: TypeError: Cannot read properties of undefined (reading 'create')
Before the upgrade to 1.0.0 it was working correctly without default.
But really it's just erroring everywhere because 'axios' is not defined:
await axios.post(endpoint, params, config);
TypeError: Cannot read properties of undefined (reading 'post')
I rolled back with "npm install [email protected]" and it works fine.
Reacted by Facundo Arias, Guilherme Paixão and Druveen Gangadhar
If I install axios 1.2.1 that is currently available then I get tons of errors like this:
Argument of type 'import("./node_modules/axios/index").AxiosRequestConfig<any>' is not assignable to parameter of type 'import("./node_modules/@nestjs/axios/node_modules/axios/index").AxiosRequestConfig<any>'.
It seems that the version mismatch breaks it all.
Edit: whoops thought this was on the nestjs github. I guess I'll have to wait for that dependency to update to fix this then.
having this error- Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'data')
at Details.js:18:1
whille trying to axios and catch the data.json this way-
const ExcelExportData = [];
let i = axios.get('https://localhost:44357/User').then(
result => { ExcelExportData = result.data }
)
.catch(error => {
console.error(error.response.data);
})
Yeah, this isn't fixed on the latest version. Same behaviour as all the above (using Gatsby). ^0.21.1 worked then borked on an update to ^1 and I've tried everything above, so downgraded to ^0.21.
Activity
gdelory commentedon Oct 5, 2022
Same issue with
get:with:
That is a major breaking change
furdzik commentedon Oct 5, 2022
I am getting similar error
My code is - instance:
And request, for example:
I am not sure where is the problem, I can't find it in my code 😞
gdelory commentedon Oct 5, 2022
That's especially an issue since the document says to use
.defaulthereAngros23 commentedon Oct 5, 2022
Yes, this form is functional, but you don't have the helpers either the types. When you use default the method create return undefined, this is the reason of the error.
furdzik commentedon Oct 6, 2022
@gdelory, @Angros23
With
.defaultapp is working correctly, but during the build it crashes.I am using
gatsbyand during the build I do the first requests.(I have build app without default, It passed, and then added default and reloaded, then was OK, but still when I try to build once again, the app not built) 😞
Before the upgrade to
1.0.0it was working correctly withoutdefault.jasonsaayman commentedon Oct 6, 2022
Will look into this asap
furdzik commentedon Oct 6, 2022
@jasonsaayman Thank you, I'm also checking, if it is not a problem with Gatsby. Tell me if there is something I can do to help
jasonsaayman commentedon Oct 6, 2022
See #5030 merged should fix this.
furdzik commentedon Oct 7, 2022
@jasonsaayman works like a dream, thank you!
jasonsaayman commentedon Oct 7, 2022
Please stay on 1.1.0 for now i need to come up with a solution that works for both commonJS and ESM
womprat commentedon Oct 12, 2022
Getting this error with Node.js
Import:
const axios = require('axios').default;
Error:
axios.defaults.withCredentials = true;
TypeError: Cannot read properties of undefined (reading 'defaults')
But really it's just erroring everywhere because 'axios' is not defined:
await axios.post(endpoint, params, config);
TypeError: Cannot read properties of undefined (reading 'post')
I rolled back with "npm install [email protected]" and it works fine.
IgnatG commentedon Oct 13, 2022
It looks like you don't need
.defaultoption anymore.this ^ worked for me
jasonsaayman commentedon Oct 14, 2022
@womprat for that the latest version should work if you drop the
.defaultbag-man commentedon Oct 14, 2022
I've noticed that...
...will reproduce this error, so you need to use:
Which is maybe something that should be fixed?
25 remaining items
gcrozariol commentedon Nov 16, 2022
This works!
kh71 commentedon Nov 18, 2022
try axios without .default it work version 1.1.3
bcetienne commentedon Nov 20, 2022
This works, thanks !
nickali2 commentedon Nov 21, 2022
This works for me, too. thanks.
ch3njust1n commentedon Nov 21, 2022
This worked for me as well on TS 4.6.4
ctsstc commentedon Dec 16, 2022
If I install axios 1.2.1 that is currently available then I get tons of errors like this:
It seems that the version mismatch breaks it all.
Edit: whoops thought this was on the nestjs github. I guess I'll have to wait for that dependency to update to fix this then.
Bat-Sheva-Sh commentedon Feb 8, 2023
having this error- Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'data')
at Details.js:18:1
whille trying to axios and catch the data.json this way-
const ExcelExportData = [];
let i = axios.get('https://localhost:44357/User').then(
result => { ExcelExportData = result.data }
)
.catch(error => {
console.error(error.response.data);
})
orgads commentedon Feb 9, 2023
Which axios version?
abhishek-goel1 commentedon May 22, 2023
Still getting this issue when trying compiling from TS to JS.
axios version 1.4.0
Any update on this?
thclark commentedon Jul 18, 2023
Yeah, this isn't fixed on the latest version. Same behaviour as all the above (using Gatsby). ^0.21.1 worked then borked on an update to ^1 and I've tried everything above, so downgraded to ^0.21.
fix: issue calling axios.create undefined
formatlos commentedon Oct 9, 2023
same problem here, pinned the version to v.1.2.2 for now
M3: trace fixes, find the fixing release, and give a verdict
Add demo GIF recorded with vhs