Note that there are some explanatory texts on larger screens.

plurals
  1. PORequireJS does not run data-main script before loading required modules
    primarykey
    data
    text
    <p>My project includes the following files:</p> <pre><code>./index.html ./js/main.js ./js/vendor/require.js ./js/viewmodel/vm.js </code></pre> <p>The <code>index.html</code> has the following relevant snippet:</p> <pre><code>&lt;script data-main="js/main.js" src="js/vendor/require.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; require(['viewmodel/vm', 'ko'], function(viewmodel, ko) { ko.applyBindings(viewmodel); } ); &lt;/script&gt; </code></pre> <p>The <code>js/main.js</code> file is as follows:</p> <pre><code>var root = this; define('jquery', ['http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.js'], function () { return root.$; }); define('ko', ['http://ajax.aspnetcdn.com/ajax/knockout/knockout-2.1.0.js'], function (ko) { return ko; }); </code></pre> <p>The <code>js/viewmodel/vm.js</code> file...</p> <pre><code>define(['jquery', 'ko'], function($, ko) { return { subject: 'world', greeting: 'hello' } } ); </code></pre> <p>When you open a browser to index.html, then the browser tries to load a file called <code>js/ko.js</code> instead of using the module defined in <code>main.js</code>. It seems like the js file pointed to by the data-main attribute is not guaranteed to run before dependency resolution. This does not seem correct to me since one purpose of the data-main js file is to define require configuration (i.e. path, shim, etc). I am using require v2.1.2. </p> <p>This works perfectly fine if I copy the contents of my <code>main.js</code> file into the script block in <code>index.html</code>. By "perfectly fine" I mean that it resolved ko to be a module and finds the appropriate CDN link to resolve ko instead of trying to download <code>./js/ko.js</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload