/client/lib files not loading


#1

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


#2

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 :scream:).

Here’s a short guide to the topic.


#3

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?


#4

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,constorvar`), 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.


#5

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