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

Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined #118

Closed
ivitivan opened this issue Oct 1, 2015 · 30 comments
Closed

Comments

@ivitivan
Copy link

ivitivan commented Oct 1, 2015

Hi!

I'm trying to use your library but I get an error:

Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined

I was using your example

axios.get('https://api.github.com/users/benjamingeorge')
  .then(function (res) {
    console.log(res.data);
  })
  .catch(function(res) {
    if(res instanceof Error) {
      console.log(res.message);
    } else {
      console.log(res.data);
    }
  });

The error happens here.
I'm using browserify and chrome 45.

@ivitivan
Copy link
Author

ivitivan commented Oct 1, 2015

I messed up in the code. Everything works fine now.

@ivitivan ivitivan closed this as completed Oct 1, 2015
@mzabriskie
Copy link
Member

Would you mind sharing what you did wrong for future reference?

@ivitivan
Copy link
Author

ivitivan commented Oct 1, 2015

Actually, I can not even reproduce the error now.

@aljones
Copy link

aljones commented Nov 4, 2015

I got this error from: axios.post('/api' [this.props.query]) If you don't see it, the comma is missing between the arguments. I tested this in node too.

> var f = function(s, a) { return { s, a }};                                      
> f('s', ['a'])                                 
{ s: 's', a: [ 'a' ] }                          
> f('s' ['a'])                                  
{ s: undefined, a: undefined }

So I guess the error is related to an argument being undefined. I'm surprised that isn't a syntax error.

@zhangjinling
Copy link

zhangjinling commented Dec 21, 2016

I also meet this question.But I also can send get and post request.
I use it in VUE,when I use Vue.use(axios);,not do otherthing .The error occured.
isURLSameOrigin.js?94c0:57 Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined
chrome : 55.0.2883.87 m

@vpiskunov
Copy link

Any solution? I am also using it with Vue.use(axios)
isURLSameOrigin.js?142d:61 Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined
Perhaps could be about the way we import it into VueJS? There doesn't seem to be any docs on how to properly import it to Vue, especially when using Webpack...

Any ideas greatly appreciated!

@rookiebulls
Copy link

@vpiskunov Maybe it's because you are using the origin axios, not a vue plugin, you should use Vue.prototype.$axios = axios if you want vue's instance to call it

@cuihj
Copy link

cuihj commented Jan 3, 2017

https://github.com/imcvampire/vue-axios

@dannypule
Copy link

dannypule commented Feb 10, 2017

I was getting this error due to the url being undefined. Was fixed after I addressed that issue.

@rohmanhm
Copy link

I got same problems guys, but I'm not using Vue.
It's happend when I process the response.data using window object, but when I just console.log(response.data) this not show any errors.

@vpiskunov
Copy link

@rohmanhm That's because the Ajax request runs on a separate isolated "thread"-like environment. You might have some luck by calling .bind(this) or .bind(window)

@rohmanhm
Copy link

rohmanhm commented Mar 3, 2017

@vpiskunov would you give me some example?

@hongyue-yue
Copy link

I am also using it with Vue.use(axios)
isURLSameOrigin.js?142d:61 Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined
when I remove 'Vue.use(axios)',it is ok

@EmadAdly
Copy link

EmadAdly commented Jul 7, 2017

If you use vue or another just

import axios from 'axios'

And use Axios normally without using Vue.use(axios)

Everything works fine

@hicaku
Copy link

hicaku commented Jul 25, 2018

Hey, when I write Vue.use(axios); in main.js I get "Uncaught ReferenceError: axios is not defined" error and it dows not change when I delete it. How can I solve this problem?

Thanks in advance!

@beipiaoyu2011
Copy link

beipiaoyu2011 commented Jul 30, 2018

If you use:
import axios from 'axios';
axios.defaults.baseURL = process.env.BASE_URL;
export default axios;

The error occurs

@mr-twady
Copy link

Using Laravel VUE JS, I experienced this same issue. This fixed it for me however -
window.axios = require('axios'); in resources/js/bootstrap.js already scaffolds axios. You wouldn't need to do Vue.use(require('axios')); in resources/js/app.js.
In my own case, this was the issue, so I removed it from app.js.

@bagaskarala
Copy link

i solved my own with deleting Vue.use(axios)

@zhaoweih
Copy link

zhaoweih commented Apr 8, 2019

I was getting this error due to the url being undefined. Was fixed after I addressed that issue.

this work for me,thank you

@Lustellz
Copy link

I got same problems guys, but I'm not using Vue.
It's happend when I process the response.data using window object, but when I just console.log(response.data) this not show any errors.

Same here. I'm not using axios, though.

@krisunni
Copy link

krisunni commented Aug 1, 2019

i solved my own with deleting Vue.use(axios)

This worked for me.

@xyznaveen
Copy link

i solved my own with deleting Vue.use(axios)

Same here don't know why tho.

@MichaelTimbes
Copy link

I think it was mentioned in an earlier comment by @rookiebulls , I am using Axios as a plug-in via Vue.use(VueAxios, axios) and what worked for me was calling axios from the Vue context by using Vue.$axios .

@vitvnua
Copy link

vitvnua commented Oct 25, 2019

i solved my own with deleting Vue.use(axios)

thanks! This worcked for me!!

@rabar1995
Copy link

install both of axios and vue-axios

import axios from 'axios'
import VueAxios from 'vue-axios'

Vue.use(VueAxios, axios)

that's worked for me

@azamatz
Copy link

azamatz commented Nov 15, 2019

my issue for this problem:
1.
import axios from 'axios';
import VueAxios from 'vue-axios';

  1. Vue.use(VueAxios, axios); // order important

@franpesca
Copy link

I solved it by removing the import in my main.js file.
So, I removed both
import axios from "axios",
and Vue.use(axios)

@andrey-lazarev
Copy link

Had the same error with bootstrap form. $form.on('submit', (event) => event.preventDefault() solved the issue.

@mamadfar
Copy link

mamadfar commented Mar 2, 2020

GuyyyyyyyyyyyyyyyyyyyyyyyyyYYYYYYYYYYYYYYYYYYYYYYYYYYYyyyyyyyyyyyyyyyyyyyyyyyyyyyS

just use this 4 line code and DONE !

import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios' ### this line is important for destroy :) 'protocol' ERROR ###

Vue.use(VueAxios, axios)

.
.
.
JUST DO THIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@mossa-Sammer
Copy link

I faced this in React.js and no solution

@axios axios locked and limited conversation to collaborators May 21, 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