kanadenipun
kanadenipun

Reputation: 47

repackaging masonry for meteor gives error " ReferenceError: window is not defined "

I wish to add desandro/masonry into my meteor project. But there was no meteor package that worked for me, so thought of creating one.

Here is package.js

'use strict';
 var packageName = 'masonryjs:masonry'; 
 Package.describe({
    name: packageName,
    summary: 'Masonryjs. cascading grid layout library',
    version: '1.1.0',
    git: 'https://github.com/desandro/masonry'
});
Package.onUse(function (api) {
    api.versionsFrom(['[email protected]', '[email protected]']);
    api.export('masonry');
    api.addFiles([
        'masonry.pkgd.js',
        'export.js'
    ]);
});

export.js

masonry = this.masonry;
delete this.masonry;

The package is added, but when i run my meteor app i get this error

W20150121-21:50:29.788(5.5)? (STDERR) /home/nipun/.meteor/packages/meteor-tool/.1.0.40.1d3bp9e++os.linux.x86_32+web.browser+web.cordova/meteor-tool-os.linux.x86_32/dev_bundle/server-lib/node_modules/fibers/future.js:173 W20150121-21:50:29.788(5.5)? (STDERR) throw(ex); W20150121-21:50:29.788(5.5)? (STDERR) ^ W20150121-21:50:29.824(5.5)? (STDERR) ReferenceError: window is not defined W20150121-21:50:29.824(5.5)? (STDERR) at masonry (packages/masonryjs:masonry/masonry.pkgd.js:147:1) W20150121-21:50:29.824(5.5)? (STDERR) at /home/nipun/development/web/mason/.meteor/local/build/programs/server/packages/masonryjs_masonry.js:2980:4 W20150121-21:50:29.824(5.5)? (STDERR) at /home/nipun/development/web/mason/.meteor/local/build/programs/server/packages/masonryjs_masonry.js:3008:3 W20150121-21:50:29.824(5.5)? (STDERR) at /home/nipun/development/web/mason/.meteor/local/build/programs/server/boot.js:205:10 W20150121-21:50:29.825(5.5)? (STDERR) at Array.forEach (native) W20150121-21:50:29.825(5.5)? (STDERR) at Function..each..forEach (/home/nipun/.meteor/packages/meteor-tool/.1.0.40.1d3bp9e++os.linux.x86_32+web.browser+web.cordova/meteor-tool-os.linux.x86_32/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11) W20150121-21:50:29.825(5.5)? (STDERR) at /home/nipun/development/web/mason/.meteor/local/build/programs/server/boot.js:116:5

Upvotes: 0

Views: 1090

Answers (1)

Kyll
Kyll

Reputation: 7139

If you don't want this package to be used on the server where window is not available, then:

api.addFiles([ 'masonry.pkgd.js', 'export.js' ], 'client');
api.export('masonry', 'client');

Upvotes: 1

Related Questions