Hey Guys,
I have several .js files in my /client/lib file. However I can not access the variables inside them and if I put a console.log in them nothing displays. This includes in the init.js.
I am running on ubuntu amazon ec2 server permissions seem fine and there are no other errors displaying.
The client folder can be viewed here: https://github.com/mikeacre/69dapp/tree/master/client
thank you,
Mike Acre
Each file’s code is wrapped in a closure to isolate it. If you want to expose something, you need to export
that thing, and then import
it wherever you need to (or you could use globals ).
Here’s a short guide to the topic.
Thank you! I was reading elsewhere the lib file was suppose to be automatic. Is there a way to make it include the whole folder?
As long as we’re talking Meteor pre v1.7, any lib/
folder will be included in the build automatically.
However, your project is using v1.7, so you will need to explicitly import
the files you want to access in the modules you want to access them from (if that makes sense!).
Alternatively, you can enable pre v1.7 behaviour by removing the entire meteor
stanza from your package.json
. In your case, that’s this entire section:
along with the trailing comma on the preceding line.
Looking at your lib/
files, you are actually using lazy globals (variable names not preceded by let,
constor
var`), so you may get away with reverting to pre v1.7 behaviour and doing nothing else.
My recommendation is to bite the bullet and refactor to use proper import/export
syntax before the code gets too big to make that a comfortable exercise.
2 Likes
I also strongly recommend adopting the modular approach and exporting / importing variables across files
However, it is possible to do what you want by dumping the files into a client/compatibility
folder, which won’t be wrapped into a new closure, allowing all of your variables to leak into the global scope
1 Like
Thanks Rob. Strangely enough, removing the entire meteor specs from the package.jason file and I am on meteor version 1.8.1. Just thought I should add this in case this helps anyone struggling with the same issue.