yandex / mapsapi-modules

Async modular system
132 stars 29 forks source link

Can't resolve module if it comes in separate <script> tag #43

Closed aristov closed 9 years ago

aristov commented 9 years ago
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>modules test</title>
</head>
<body>
<script>
    /* here comes modules v0.1.0 source */
</script>
<script>
modules.require(['A'], function(A) {
    A();
});
</script>
<script>
modules.define('A', function(provide) {
    provide(function() { console.log('test')});
});
</script>
</body>
</html>

It reproduces sometimes. Open this HTML in Chrome, Yandex, Opera with opened console and press cmd+r until we get JS-error: Uncaught Error: Required module "A" can't be resolved. If we remove </script><script> between require and define then we can not reproduce this bug.

dfilatov commented 9 years ago

It's side effects of nextTick which is not garanteed to be applied after all of <script/>s are executed. I haven't seen any way to fix it. I suggest you to move modules.require to the last <script/> on the page.