Import best practices

Yep, we are using lodash straight from npm in our app.

K, Iā€™ll try it out later, so far Iā€™m still working on trouble with FindFromPublication after the upgrade.

1 Like

OMG I thought I was the only one. This has been so frustrating for me.
I have done a few quick prototypes with Meteor prior to 1.3 and loved that the load order was taken care of for me, because I havenā€™t used modules and explicit import/export notations before (apart from the very occasional import on small Node apps I experimented with before, but nothing large enough that it needed any complicated structuring).

Now, I can definitely see the benefit of the whole concept and also the single-point-of-entry makes total sense in terms of scalability.

But I am trying to build my first bigger app (ā€˜biggerā€™ meaning a more complex structure and feature set etc), and with every little bit of functionality I am doing my utmost to read the guide first, regarding structuring the folders and files etcā€¦ I keep getting confused by which file is importing which other file from where and why. And when something doesnā€™t work, I find out some file isnā€™t actually being called at all or imported into the wrong ā€˜parentā€™ fileā€¦

So as a beginner developer, who got into Meteor for the simplicity and ease of entry, I have to say Meteor 1.3 is a huuuge challenge.
So after reading this thread (thanks to everyone for their very helpful explanations, much appreciated!), I decided to redesign the folder structure on paper with a flow chart as to where each import comes from and where each export goes to etc.

Hopefully thatā€™ll restore my sanity eventually.

5 Likes

@reel i think it make sense and the code is much cleaner since you donā€™t have to type all the imports again and againā€¦ Thanks for sharingā€¦ iā€™ll be using this on my next project

One drawback is if you want to use webpack, you will have some problems with relative path /ā€¦

I completely agree. I started doing the tutorials right before 1.3 dropped (wasnā€™t aware it was coming). It was so fun, and easy! Then I came back a week later to finish the tutorial. Everything changed.

I felt like an Italian mobster, ā€œmy imports got imports got imports got importsā€. Most of the time my code was right but an import was missing in the chain. I do understand where their going, but the learning curve went from x to x^2.

Iā€™m going to give it another try in the coming weeks.

1 Like

It didnā€™t become clear until my app started to grow, but I now see the example is a good pattern. All of the comments by hwillson above are right on the money.

1 Like

Just wanted to say that I actually had to reach this thread in order to even be aware of the import chain that this pattern aims at. The whole server/main and register-api thing are not mentioned in the app structure guide. Could have saved me a lot of time to see it there.

2 Likes

Please file an issue!

1 Like

@skirunman Iā€™m having a strange intermittent error. At times _ refers to underscore and other times _ lodash. Have you seen this error? It is not very consistent. Often times if I >meteor npm remove lodash, and the install again, it will revert _ to underscore.

I love it ā€¦ brilliant. Best gem in the thread :slight_smile: