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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axios instance not working after update to 0.21.4 from 0.21.1 #4027

Closed
Alta1re opened this issue Sep 6, 2021 · 15 comments · Fixed by #4041
Closed

Axios instance not working after update to 0.21.4 from 0.21.1 #4027

Alta1re opened this issue Sep 6, 2021 · 15 comments · Fixed by #4041

Comments

@Alta1re
Copy link

Alta1re commented Sep 6, 2021

Describe the bug

I updated from 0.21.1 to 0.21.4 in my react-native application, where i am using an axios-instance.
After the update, i got "Network Error".
When i omitted the instance, and used axios directly, it worked, but not with instance.
After downgrading back to 0.21.1 everything works fine again.

To Reproduce

Just used a simple instance, like shown in the docs.

Expected behavior

Axios should work with instance, or, if the usage of instance changed, we an update in the docs.

Environment

Axios Version 0.21.1 / 0.21.4
Additional Library Versions [e.g. React 16.13.1, React Native SDK42]

Additional context/Screenshots

Add any other context about the problem here. If applicable, add screenshots to help explain.

@MaximMonin
Copy link

MaximMonin commented Sep 6, 2021

NodeJs 14 or 16 have this problem also .... half http/https queries doesnt work with this update sending "Bad json request" as reply

@jasonsaayman
Copy link
Member

Which version of node are you using?

@MaximMonin
Copy link

MaximMonin commented Sep 7, 2021

Which version of node are you using?

Right now 14.17.1 (tried also 14.17.6, and 16.8.0) and returned to 0.21.1 axios.
If I see it right the problem already discussed in closed topics but some cases still created "Bas json data"

    var rpcdata = JSON.stringify(requestData);
    if (rpcdata == '{}') {   // For method == Get sometimes api returns Error so fixing it
      rpcdata = '';
    }
    var headers = {'Content-Type': 'application/json', 'Accept': 'application/json'};
    if (customHeaders) {
      headers = customHeaders;
    }
    if (token && token.length > 0) {
      headers ['X-Auth-Token'] = token;
    }

    url = encodeURI(url);

    axios({
      url: url,
      method: method,
      data: rpcdata,
      httpAgent: httpagent,
      httpsAgent: httpsagent,
      timeout: timeout * 1000,
      headers: headers
    })
    .then( function (response) {

this code working with 0.21.1 but fails with 0.21.4

@csvan
Copy link

csvan commented Sep 7, 2021

Latest version also breaks unit tests since the validators are now breaking (cannot read 'split' of undefined)

@Alta1re
Copy link
Author

Alta1re commented Sep 7, 2021

I am using node V14.16.0

@nerdbeere
Copy link
Contributor

@Alta1re I tried reproducing this on runkit without success: https://runkit.com/nerdbeere/613710790e31ee0008798854
I also tried it on my machine with node 14.6 which also works.

Can you try building a minimal case where this bug is visible?

@luhc228
Copy link

luhc228 commented Sep 7, 2021

Also not work with axios@0.21.4, but work with axios@0.21.1.

my Node.js version is v14.16.0

@luhc228
Copy link

luhc228 commented Sep 7, 2021

I fetch my api in my react component. I got the response successfully.
image

image

But the res object has not been consoled.

@Alta1re
Copy link
Author

Alta1re commented Sep 7, 2021

I fetch my api in my react component. I got the response successfully.

But you are not using an axios-instance.

With using axios directly i don´t have problems, too.
And i even get my response object.

@Alta1re
Copy link
Author

Alta1re commented Sep 7, 2021

@Alta1re I tried reproducing this on runkit without success: https://runkit.com/nerdbeere/613710790e31ee0008798854
I also tried it on my machine with node 14.6 which also works.

Can you try building a minimal case where this bug is visible?

When i create a bare react-app, and just insert an axios-instance and an axios call in App.js, i can´t reproduce this too.
But in my existing application (react-native) it´s definitely just changing the version of axios which changed the result of fetching.
At the moment i am quite busy with my application, i will do some more test, when i am finished.

@jasonsaayman
Copy link
Member

Mm seems odd can you try give us a reproducible example @Alta1re

@alvesmog
Copy link

alvesmog commented Sep 9, 2021

Latest version also breaks unit tests since the validators are now breaking (cannot read 'split' of undefined)

I am having the same issue. It is related to the package.json version on axios.

For some reason, this isn't getting the proper version.

I'm using node 12

@jasonsaayman
Copy link
Member

Cool there is a fix #4029 as soon as it is rebased I will do a release

This was linked to pull requests Sep 9, 2021
@varemenos
Copy link

Sorry to bother but was this ever released? I see that both this issue and #4029 are closed but no new version above 0.21.4.

@freddiegar
Copy link

You can use this version: v0.22.0 or +

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