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 0.19.0 issue #2397

Closed
sm2017 opened this issue Sep 8, 2019 · 11 comments
Closed

Axios 0.19.0 issue #2397

sm2017 opened this issue Sep 8, 2019 · 11 comments

Comments

@sm2017
Copy link

sm2017 commented Sep 8, 2019

Describe the bug
I have problem with axios 0.19.0 , my code works well with axios 0.18.0 , I think axios 19 has issue with baseUrl config

To Reproduce

https://runkit.com/sm2017/5d748f34dda96b001a60f5d0

var axios = require("axios")

const instance = axios.create({
  baseUrl:'https://github.com/axios',
});

await instance.get('/axios');
Error: connect ECONNREFUSED 127.0.0.1:80
A stack trace for this error could not be retrieved because stack was already called.

Expected behavior
It must load axios github page

Environment:

  • Axios Version [e.g. 0.18.0] 0.0.19
  • OS: [e.g. iOS 12.1.0, OSX 10.13.4] , windows 10
  • Browser [e.g. Chrome, Safari] nodejs
  • Browser Version [e.g. 22] v10.15.3
  • Additional Library Versions [e.g. React 16.7, React Native 0.58.0] I test in react native 0.60.5 too

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

@sm2017
Copy link
Author

sm2017 commented Sep 11, 2019

Reply please

@dingziqi
Copy link

It's a case problem.Use baseURL

@lcsvcn
Copy link

lcsvcn commented Sep 11, 2019

I am having same issue:

const test= axios.create({
  baseURL: CONSTANTS.BASEURL,
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  auth: {
    username: CONSTANTS.USERNAME,
    password: CONSTANTS.PASSWORD
  },
  timeout: 10000,
});

axios.all([
         test.get('path1/'),
          test..get('path2/')
]).then(axios.spread((path1, path2) => {
             // success code
})
).catch((path1, path2) => {
         // error code
});

on 0.18.0 it goes inside success code

on 0.19.0 it goes inside error code

@cesar18pena
Copy link

@sm2017 it is just a typo error, should be:

const instance = axios.create({
  baseURL:'https://github.com/axios',
});

instead of

const instance = axios.create({
  baseUrl:'https://github.com/axios',
});

@sm2017 sm2017 closed this as completed Sep 12, 2019
@sm2017 sm2017 reopened this Sep 14, 2019
@sm2017
Copy link
Author

sm2017 commented Sep 14, 2019

@dingziqi , @cesar18pena what do you think about the following codes

var axios = require("axios@0.18.0")

const instance = axios.create({
  baseURL:'https://postman-echo.com/',
  url:'/get',
  params:{
    "foo1": "bar1",
    "foo2": "bar2"
  }
});

const {data} = await instance.request();

console.log(data)
var axios = require("axios")

const instance = axios.create({
  baseURL:'https://postman-echo.com/',
  url:'/get',
  params:{
    "foo1": "bar1",
    "foo2": "bar2"
  }
});

const {data} = await instance.request();

console.log(data)

https://runkit.com/embed/nzbzdjc4auv7 works well but https://runkit.com/embed/lro4kcp7w8ir not

@sm2017
Copy link
Author

sm2017 commented Sep 26, 2019

Any idea?

@dingziqi
Copy link

dingziqi commented Sep 27, 2019

The rule of merge config is changed in 0.19.0,(see https://github.com/axios/axios/blob/master/lib/core/mergeConfig.js), the params, url in axios is dropped.

@sm2017
Copy link
Author

sm2017 commented Sep 27, 2019

So it is a brwaking change

@yasuf
Copy link
Collaborator

yasuf commented Nov 5, 2019

I think I figured out why, there was a change with defaults inside .request that makes it so that the default headers aren't set, I'll try to push a PR to fix this whenever I get a chance, relevant lines:

0.18 version

config = utils.merge(defaults, {method: 'get'}, this.defaults, config);

0.19 version

config = mergeConfig(this.defaults, config);

good catch!

@yasuf
Copy link
Collaborator

yasuf commented Nov 5, 2019

@sm2017 can you test if the request works with this change? #2516

@chinesedfan
Copy link
Collaborator

Tested with 0.19.1, and it works.

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants