Vue: _directives.length ERROR: Cannot read property 'length' of null

Created on 15 Jan 2015  路  6Comments  路  Source: vuejs/vue

Using Vueify in an app (compiled in DEV) I get the following error:

Uncaught TypeError: Cannot read property 'length' of null

From script.js:7557

var originalDirCount = vm._directives.length

I use no custom directives. Error occurs only sometimes, very weird.

Any idea anyone?
Thanks!

More context on script.js:

/**
       * A linker function to be called on a already compiled
       * piece of DOM, which instantiates all directive
       * instances.
       *
       * @param {Vue} vm
       * @param {Element|DocumentFragment} el
       * @return {Function|undefined}
       */

      return function link (vm, el) {
        var originalDirCount = vm._directives.length
        if (paramsLinkFn) paramsLinkFn(vm, el)
        if (nodeLinkFn) nodeLinkFn(vm, el)
        if (childLinkFn) childLinkFn(vm, el.childNodes)

All 6 comments

I'm experiencing the same error. Had to revert back to 0.11.3 to make my app work again. This is almost definitely a bug. Could try doing some further investigations.

This is actually pretty weird because it indicates the linker is called when the target vm is already destroyed. I would need a more isolated reproduction to identify the cause.

@kvdmolen can you repro this issue in a jsfiddle so we can all look into it?

@agonbina I will definitely try to pinpoint & isolate, but difficult because it happens only sometimes.
Though, it does happen right after an emit event:

var store = module.exports = new Emitter()
store.emit('...')

After which (at the receiver) the v-component should be updated (which is then not executed):

<div v-component="{{page}}"></div>

Perhaps that gives some first insight. It's according the hackernews-example. I'll be working on isolating the issue!

Please see my comment on issue #654 above. I believe these issue are not the same but are related.

Events can cause components to be added or removed by changing variables which effect v-if or v-component="{{someVar}}". This alters event propagation. In the case of #654, the list of event listeners may change while the event code is traversing that same list.

I think the event propagation code should make a copy of the event listener list when it begins processing the list. Then while iterating through the list it should check that each listener still exists before calling update().

Closing since this has most likely been fixed by v-if and transclusion refactor.

Was this page helpful?
0 / 5 - 0 ratings