Vue-resource: "Cannot read property 'options' of undefined" error when using Vue.http.* methods

Created on 31 Dec 2015  路  8Comments  路  Source: pagekit/vue-resource

Hi, I'm using http service like following code but it throws an error Cannot read property 'options' of undefined

code:

import Vue from 'vue'; // v1.0.13
import VueResource from 'vue-resource'; // v0.5.1

Vue.use(VueResource);

Vue.http
  .get(url)
  .then((response) => {
    // do something
  });

error:

Uncaught TypeError: Cannot read property 'options' of undefined

The error seems to be occurred at https://github.com/vuejs/vue-resource/blob/0.5.1/src%2Fhttp.js#L23

Is it a bug?
Or is there wrong usage in my code?

Most helpful comment

I resolved the problem and it is from my webpack configuration.
It works after I fixed to prevent babel-loader to convert scripts in node_modules.

{test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/}

I'm sorry to trouble and confuse you.

All 8 comments

This issue is fix in v0.6.0

@ktsn If your problem was resolved, then please close out this issue.

Sorry for the late response.

There is another error when I have checked v0.6.0.
The error is not occurred if I use http services from a vm instance.

Uncaught TypeError: Cannot read property '$vm' of undefined

@ktsn Can you provide a jsFiddle that reproduces the problem?

@amirrustam
I could not reproduce the error on jsFiddle...
I looked into about the error and I think it happens when loading vue-resource by Webpack.

The error is thrown at https://github.com/vuejs/vue-resource/blob/master/src/http/index.js#L16
this === undefined at line 16 when I load vue-resource by Webpack.
But if I load it by <script> element, this === window and success to send http request.

I resolved the problem and it is from my webpack configuration.
It works after I fixed to prevent babel-loader to convert scripts in node_modules.

{test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/}

I'm sorry to trouble and confuse you.

I had the same problem when trying to pass vue-resource.js throught babel.
Uncaught TypeError: Cannot read property '$vm' of undefined

@adrianthedev use exclude: /node_modules/ configuration, and it can works.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ayyobro picture ayyobro  路  3Comments

odranoelBR picture odranoelBR  路  6Comments

nivv picture nivv  路  4Comments

santigraviano picture santigraviano  路  5Comments

christophwolff picture christophwolff  路  6Comments