broccoli-caching-writer fails with "Cannot read property 'images/.DS_Store' of undefined"

221 views Asked by At

I am fairly new to broccoli and have been trying to write a simple plugin to use with ember.js. I used broccoli-caching-writer in my index.js as described on the github page for broccoli-caching-writer:

var CachingWriter = require('broccoli-caching-writer');


module.exports = CachingWriter.extend({
    init: function(inputTrees, options)
    {   
        console.log('Initializing plugin with tree');
        console.log(inputTrees);
        console.log(options);
        this.inputTrees = inputTrees;

    },
    updateCache: function(srcPaths, destDir) {
        console.log('updateCache called with srcPaths and destDir');
        console.log(srcPaths);
        console.log(destDir);
    }
});

I then imported the plugin into my ember app (that uses ember CLI) and configured the following in my .brocfile

var plugin = require('broccoli-my-plugin');
var merge = require('broccoli-merge-trees');

pluginTree = new svgSpriter(['images'], {some: 'options'});
....
....
module.exports = merge([app.toTree(),pluginTree]);

Running the above with ember build command gives the following output (paths edited for privacy reasons):

    Build failed.
Cannot read property 'images/.DS_Store' of undefined
TypeError: Cannot read property 'images/.DS_Store' of undefined
    at CoreObject.proto.shouldBeIgnored (/node_modules/broccoli-svg-sprite/node_modules/broccoli-caching-writer/index.js:135:33)
    at CoreObject.proto.keyForTree (/node_modules/broccoli-svg-sprite/node_modules/broccoli-caching-writer/index.js:277:14)
    at CoreObject.<anonymous> (/node_modules/broccoli-caching-writer/index.js:267:21)
    at Array.map (native)
    at CoreObject.proto.keyForTree (/node_modules/broccoli-caching-writer/index.js:266:24)
    at /node_modules/broccoli-caching-writer/index.js:87:20
    at lib$rsvp$$internal$$tryCatch (/node_modules/broccoli-svg-sprite/node_modules/broccoli-caching-writer/node_modules/rsvp/dist/rsvp.js:489:16)
    at lib$rsvp$$internal$$invokeCallback (/node_modules/broccoli-svg-sprite/node_modules/broccoli-caching-writer/node_modules/rsvp/dist/rsvp.js:501:17)
    at lib$rsvp$$internal$$publish (/node_modules/broccoli-svg-sprite/node_modules/broccoli-caching-writer/node_modules/rsvp/dist/rsvp.js:472:11)
    at lib$rsvp$asap$$flush (/node_modules/broccoli-caching-writer/node_modules/rsvp/dist/rsvp.js:1290:9)

It seems like the plugin is trying to check whether to ignore the path or not, but the options passed to caching writer does not have filterfromcache option defined, so the above should work? Not sure if I'm missing something?

Any help would be appreciated.

1

There are 1 answers

0
MojoJojo On

Okay, I think the example for overriding the init method needs a little update for newbies like me. It turns out that the init method in the parent module wasn't being called. Adding the following to my init method fixed it:

      CachingWriter.prototype.init.call(this, inputTrees, options);

Not sure if there is a better way though.