vazco / universe-modules

Use ES6 / ES2015 modules in Meteor with SystemJS
https://atmospherejs.com/universe/modules
MIT License
52 stars 7 forks source link

Module load order is filename sensitive ! #8

Closed vjau closed 9 years ago

vjau commented 9 years ago

I think it's a bug introduced by version 0.3. Create a meteor app called ddd Then a module in a file called e.import.js Write an import statement in ddd.js : System.import('e') or System.import('e.import') universe:modules will complain that e doesn't exist. If you name the module a.import.js it will work...

MacRusher commented 9 years ago

Definitely a bug, this shouldn't happen. I will take a look at it tomorrow.

MacRusher commented 9 years ago

Ok I spend really really lots of time on it today. I'm afraid that this won't be a easy fix, at least not without disabling Blaze support.

Modules (*.import.js(x) files) are created in the same order as any other files in Meteor project, and there is no easy way to alter this behavior with current Meteor file loader system.

So if you call System.import('z') in a file a.js in the same directory, "z" module isn't ready yet. It's a promise, but this promise is trying to resolve right now and it fails. This promise could wait for all files to load (wait for Meteor.startup) but then... Blaze template won't work because they require that all helpers/events are assign to Template.templateName objects before the startup. This is really often use case so we cannot drop it.

You're right that this worked in < 0.3.0, but it was working due to a bug.

For now the easiest fix is to put all modules into some subdirectory (it doesn't have to be lib) so they will be ready once you use System.import. Inside the same directory you can use main.js which is loaded last.

I'm marking this as wontfix but I hope that I'll find a solution for that. Right now I don't know how to do it without using really pesky hacks, and general stability and predictability is more important for me.

If someone have some ideas how to tackle this problem please let me know.