requirejs/require-cs

Entry point issue

Closed this issue · 6 comments

I include the following script tag in the head of the page:

<script type='text/javascript' src='requirejs.js' data-main='cs!main'></script>

In the console, I see a request to main.cs run fine. There is then an additional call to main.js, and a script error notice in the debugger.

The debug log is -

GET file://localhost/Users/guybedford/Projects/test/www/js/main.coffee?bust=1340365609996 cs.js:66
GET file://localhost/Users/guybedford/Projects/test/www/js/main.js?bust=1340365609996 requirejs.js:1831
Uncaught Error: Script error
http://requirejs.org/docs/errors.html#scripterror requirejs.js:175
makeError requirejs.js:175
context.onScriptError requirejs.js:1649
Uncaught Error: Load timeout for modules: cs!main_unnormalized2,cs!main
http://requirejs.org/docs/errors.html#timeout

I saw this happen when I upgraded to RequireJS 2.0.0 from 1.0.0 (using the same require-cs). My solution was just to re-write my short main file in javascript.

I think plugins can't notify requirejs they ran the main. Requirejs fetches the file using the plugin, the plugin runs the file, then requirejs fetches the file again because it doesn't know what the plugin did.

Then again, it used to work fine.

Do either one of you have a test case I can try, or how does yours differ from the following?

I modified demo/index.html in this project to be this:

    <script>
        var require = {
            baseUrl: 'lib',
            paths: {
                cs: '../../cs',
                CoffeeScript: '../../CoffeeScript'
            }
        };
    </script>
    <script data-main="cs!csmain" src="lib/require.js"></script>

and that loaded for me with no errors. I was using require.js 2.0.2.

Apologies, it seems I should have checked this on the latest version.

It is working fine with require.js 2.0.2.

I've been playing around with this some more, and am still getting some strange behaviour.

I have a file called test.html in my js folder. I have a module, called 'module', with a file 'module.js' in the module folder.

My config is -

<script>
        var require = {
          baseUrl: '' //(blank since a '.' doesn't seem to be valid)
        };
</script>
<script data-main="cs!module/module" src="require.js"></script>

Now this shows a request to:

GET file://.../www/js/cs!module/module.js

It seems that it is the use of a sub-folder in the plugin file path that causes the issue.

If I change data-main to: "cs!module", it works fine.

(NB 'module' is a bad example name, because I notice it actually works by picking up as a system require!... take it as a placeholder.)

Why pass the baseUrl of ''? instead of just not setting it? '.' should be a valid baseUrl value in general, or do you mean using '.' results in a bad path translation?

Oh, sounds like this is requirejs/requirejs#351 so I'll close this issue and track it over in that other issue.