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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1.0.0] TypeError: Cannot read properties of undefined (reading 'create') #5011
Comments
Same issue with
with:
That is a major breaking change |
I am getting similar error
My code is - instance: const axios = require('axios');
const { gateway } = require('../config/environment');
const { version } = require('../../package.json');
const api = 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) => { throw error; }
);
module.exports = { api }; And request, for example: const { api } = require('../config/api');
const getSomeEndpoint = (data) => (
api.post('endpoint', data)
);
module.exports = { getSomeEndpoint }; I am not sure where is the problem, I can't find it in my code 😞 |
That's especially an issue since the document says to use |
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
Before the upgrade to |
Will look into this asap |
@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 |
See #5030 merged should fix this. |
@jasonsaayman works like a dream, thank you! |
Please stay on 1.1.0 for now i need to come up with a solution that works for both commonJS and ESM |
Getting this error with Node.js Import: Error: But really it's just erroring everywhere because 'axios' is not defined: I rolled back with "npm install axios@0.27.2" and it works fine. |
It looks like you don't need const axios = require('axios');
const client = axios.create({ ...}); this ^ worked for me |
@womprat for that the latest version should work if you drop the |
I've noticed that...
...will reproduce this error, so you need to use:
Which is maybe something that should be fixed? |
Removing |
With 1.1.3 and TS, this code: import axios from 'axios';
const axiosClient = axios.create(); is transpiled to: const axios_1 = require("axios");
const axiosClient = axios_1.default.create(); and it fails. |
@orgads thanks I will have a look |
Same issue with looking for a solution for typescript users. require is still required Works great if you put the past version.
|
Same issue post, spent quite some time on this. Version 1.1.0 works fine though |
To write a program I installed Axios with |
I am also able to reproduce this issue via following method Sample TS Code
Now after compiling this code
We will get the following error
Now the only work around is to switch back to version 1.1.0 |
Same issue
|
Same issue here, Had to switch back to 1.1.0 - huge breaking change |
following |
I think this is related to (and should be fixed by) #5174. The fix should be released soon. |
I'm getting this error, not sure if it is related to this issue or not.
|
+1 Following the topic to know when it will be fixed |
+1 same here with |
Please try the latest pre-release and let me know |
Seems to work for me Thank you |
Worked for me too, thanks! |
This works! |
try axios without .default it work version 1.1.3
|
This works, thanks ! |
This works for me, too. thanks. |
This worked for me as well on TS 4.6.4 |
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. |
having this error- Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'data') |
Which axios version? |
Still getting this issue when trying compiling from TS to JS. |
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. |
The problem is with v1 and in combination with commonjs module such as this SDK. axios/axios#5011
same problem here, pinned the version to v.1.2.2 for now |
Describe the bug
To Reproduce
Expected behavior
Runs without error.
Environment
Additional context/Screenshots
TypeError: Cannot read properties of undefined (reading 'create')
(I could not see any breaking change)
The text was updated successfully, but these errors were encountered: