[Solved] Settings in package.js of my package mask settings in .meteor/packages for the rest of my app

I am trying to move some code out my app and into packages, but when I resolve the dependencies of my packages I end up losing dependencies for all the client-side files of my app that are not in the package.

My browser console log fills up with nearly 100 error messages like :

Uncaught ReferenceError: Template is not defined
Uncaught ReferenceError: Meteor is not defined
Uncaught ReferenceError: Mongo is not defined
Uncaught ReferenceError: App is not defined

(the server-side log shows no errors)

How can the settings in a package kill the ones specified for the whole app?

Is it obvious what I must be doing wrong, or is more info required.

FWIW : If I move my two packages from the packages directory to a directory called modules the entire application works correctly.

Ok, I just went through randomly trying one api.use() phrase after another on those dependencies. I then noticed that the first error in that long list of them did refer to a file in my package ("Uncaught ReferenceError: Router is not defined")

I added api.use('iron:router') to my packages.js and everything started working ok.

It sure would be nice if Meteor was more helpful in such cases.

Meteor does not assume that your package dependencies would be the same as app dependencies.

Most packages in fact don’t need mongo, template and many other default app packages.

Therefore, while you don’t need to declare them as your app dependencies in your app routes, (since meteor-platform dependency takes care of that) you do need to add those dependencies on your package code if you actually need them.

Thanks for those clarifications. The problem I found with packages is the difficulty of tracking down the cause if you get something wrong.

For that reason, I made two very small experiments to make sure I understood error messages and any quirks of configuration. I published them on GitHub as warehouseman / pkgd-todos and warehouseman / fliptext. The latter appears in AtmosphereJS as warehouseman:fliptext

1 Like

I hear you. Although the error messages on your console tend to hint to what’s missing in the form of foo is undefined or foo does not have a property bar it is still a cumbersome task to hunt down meteor dependencies.

Nice experiments by the way. Definitely calls for two separate blog posts. Especially the todos! Kudos!