Hello! I’m in the process of separating my app into packages. I’m closely following the structure of the Telescope meteor project. I’ve run into a problem when trying to access the Template object in JS code from a package I create.
TLDR; I can access the Template object through logging from a JS file in my package, but if I try to work with the Template object in that same file, I get a “Cannot read property X of undefined” error.
Here’s the full description of my setup and issue:
I’m running Meteor 1.2.1
app:lib - Package.onUse function:
api.use([ // meteor & shared atmosphere packages here ]);
api.export([ 'App', '_', 'Meteor', 'Template', 'Blaze' ]);
app:core - Package.onUse function:
api.use([ 'app:lib@0.1.0', 'app:start@0.1.0', // other local packages here ]);
app:start - Package.onUse function:
api.use([ 'app:lib@0.1.0', // a couple other packages ]);
api.addFiles([ 'lib/start.js' ], ['client','server']);
api.addFiles([ 'lib/client/templates/start_layout.html', // renders fine 'lib/client/templates/start_form.html' // renders fine ], ['client']);
lib/start.js
I can log the Template object and my Template instance to the console fine.
console.log(Template) // works
console.log(Template.start_form) // works
If I try to do anything with the Template object, like try to setup helpers or events on a specific template, or even just set a global helper with Template.registerHelper(), I get an error:
Template.start_form.onRendered = function() { console.log("test"); }
TypeError: Cannot read property 'start_form' of undefined at Package (lib/start.js:9:9)
Has anyone experienced this before? Or any tips on how I can continue to troubleshoot? Any help is hugely appreciated!
-Alan