requirejs / requirejs

A file and module loader for JavaScript
https://requirejs.org/
Other
12.95k stars 2.37k forks source link

Opera can't load inline modules #357

Open frankradocaj opened 12 years ago

frankradocaj commented 12 years ago

I have the following inline module that I use to bootstrap data into my app. Works in all browsers except Opera (I've tried Opera v10.0-12.0. Using requirejs v2.0.2.

<script type="text/javascript">
    define('bootstrap-data', function() {
      return  { 
        myData: 'stuff'
        };
    });
</script>

And my main.js:

require.config({
    baseUrl: '/js'
    ... config bits...
    }
});

require([
    'app',
    'bootstrap-data' // Get bootstrapped data from inline module
],
function (app, bootstrapData) {
    // Start the app as soon as the DOM is ready, loading in the bootstrapped data
    $(function () {
        app.start(bootstrapData);
    });
});

Exception thrown in Opera. Seems to be trying to load the bootstrapData via a call to bootstrap-data.js on the server:

Linked script not loaded bootstrap-data.js
Uncaught exception: Error: Script error
http://requirejs.org/docs/errors.html#scripterror

Error thrown at line 1803, column 8 in <anonymous function: req.onError>(err) in http://localhost:65060/js/lib/require/require.js?v=2:
throw err;
called from line 533, column 20 in onError(err, errback) in http://localhost:65060/js/libs/require/require.js?v=2:
req.onError(err);
called from line 1698, column 20 in <anonymous function: onScriptError>(evt) in http://localhost:65060/js/libs/require/require.js?v=2:
return onError(makeError('scripterror', 'Script error', evt, [data.id]));

Error created at line 192, column 8 in makeError(id, msg, err, requireModules) in http://localhost:65060/js/libs/require/require.js?v=2:
var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id);
called from line 1698, column 20 in <anonymous function: onScriptError>(evt) in http://localhost:65060/js/libs/require/require.js?v=2:
return onError(makeError('scripterror', 'Script error', evt, [data.id]));
jrburke commented 12 years ago

In the config bits, are you using a 'context" config?

frankradocaj commented 12 years ago

No. But I am using the following requirejs plugins, if that helps:

    noext: '../libs/require/noext', //https://github.com/millermedeiros/requirejs-plugins
    async: '../libs/require/async', // Required by google loader
    goog: '../libs/require/goog', // Google async loader
    propertyParser: '../libs/require/propertyparser', // Required by google loader

My full code is in a Github project: https://github.com/Bowerbird/bowerbird-web/blob/master/Src/Bowerbird.Website/js/main.js

jrburke commented 12 years ago

Do you have a test URL I can hit to debug? I do not have the tooling parts set up to do the server parts of that code snippet.

frankradocaj commented 12 years ago

Here is a Gist that exposes the essence of the issue: https://gist.github.com/3037069. Needs require.js copied into the directory too.

FWIW, my testing has shown it works in:

And it doesn't work in:

jrburke commented 12 years ago

Thanks! I can reproduce with that gist. I filed a bug with Opera, because I believe it is an issue with the browser. I will post back here as I hear things.

frankradocaj commented 12 years ago

Thanks James! Do you know of any workaround where I could load the bootstrapped data inline and still be requirejs/AMD compatible?

jrburke commented 12 years ago

In the meantime, do not use data-main, do a require([]) for it after the inline define.