question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property '$vm' of undefined

See original GitHub issue

code like these:

const Vue = require('vue');
const VueRouter = require('vue-router');
const App = require('./app.vue');

Vue.use(VueRouter);
Vue.use(VueResource);
let app = Vue.extend(App);

Vue.http.post( '/url').then((res)=> {}, (err)=> {});

the webpack loader config like this:

  loaders: [
      {
        test: /\.vue$/, loader: 'vue-loader'
      },
      {
        test: /\.js$/, loader: 'babel-loader'
      }
    ]

babel config: { "presets": ["es2015","stage-2"] }

and then the error:** Uncaught TypeError: Cannot read property ‘$vm’ of undefined**

error code part:

function Http(url, options) {

        var client = Client,
            request,
            promise;

        Http.interceptors.forEach(function (handler) {
            client = interceptor(handler, this.$vm)(client);
        }, this);

        options = _.isObject(url) ? url : _.extend({ url: url }, options);
        request = _.merge({}, Http.options, this.$options, options);
        promise = client(request).bind(this.$vm).then(function (response) {

            return response.ok ? response : Promise.reject(response);
        }, function (response) {

            if (response instanceof Error) {
                _.error(response);
            }

            return Promise.reject(response);
        });

        if (request.success) {
            promise.success(request.success);
        }

        if (request.error) {
            promise.error(request.error);
        }

        return promise;
    }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
steffanscommented, Jun 15, 2016

Bable with es2015 presets adds use strict mode which causes this issue. Can you try v0.7.4 which will work in strict mode as it supposed to.

0reactions
Emiya0306commented, Jun 10, 2016

@leaves4j See this issue, it can resolve the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue unit tests - cannot read property 't' of undefined
I'm using jest to run vue unit tests to check the output of individual components. The component uses vuetify. I create an instance...
Read more >
Wrapper | Vue Test Utils
Properties. # vm. Component (read-only): This is the Vue instance. You can access all the instance methods and properties of a vm with...
Read more >
[vue warn]: error in render: "typeerror: cannot read properties ...
The problem is caused by duplicated loading of vue.js. Your code only loads the standalone build of vue.js ( import Vue from vue/dist/vue.js)...
Read more >
Vue warn]: Error in render: "TypeError: Cannot read property ...
Coding example for the question [Vue warn]: Error in render: "TypeError: Cannot read property '"' of undefined"-Vue.js.
Read more >
Vue-resource: cannot read property '$http' of undefined
I've tried called $http as 'this.$http', and the same thing happens. I know that I don't fully understand what governs the usage of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found