Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get real errors with requirejs?

I'm new to requireJS, and I'm trying to figure out why I can't get normal errors.

I'm using this, right after the requirejs file is loaded, but before any modules are loaded:

requirejs.onError = function (err) {
    console.log(err.requireType);
    if (err.requireType === 'timeout') {
        console.log('modules: ' + err.requireModules);
    }

    throw err;
};

But I'm still getting the completley vague error:

Error: script error
http://requirejs.org/docs/errors.html#scripterror @ http://localhost/wampir/lib/require.js:8
"scripterror"

Is there a way to make this give me the actual error and line number?

I've seen this question but I've tried several answers from there, and they don't change anything...

like image 730
Brigand Avatar asked Oct 15 '13 03:10

Brigand


People also ask

Is RequireJS still relevant?

RequireJS is, in web-terms, an old technology now (some might say ancient), but it is still in wide use and there have been a number of questions about RequireJS and DataTables recently.

How do you fix mismatched anonymous definition module?

To fix the problem, you must update your JavaScript define methods within RequireJS, according to following documentation: https://requirejs.org/docs/api.html#define.

What is the difference between RequireJS CommonJS and AMD loaders?

RequireJS is probably the most popular implementation of AMD. One major difference from CommonJS is that AMD specifies that modules are loaded asynchronously - that means modules are loaded in parallel, as opposed to blocking the execution by waiting for a load to finish.

Is RequireJS synchronous?

Is RequireJS synchronous? So, RequireJS doesn't support it. From your use case it seems that you don't need synchronous RequireJS, you need to return result asynchronously. AMD pattern allows to define dependencies and load them asynchronously, but module's factory function must return result synchronously.


1 Answers

Remove the "timeout" check. It's keeping you from seeing the modules you're having a problem with unless the problem happens to be a timeout.

requirejs.onError = function (err) {
    console.log(err.requireType);
    console.log('modules: ' + err.requireModules);
    throw err;
};
like image 71
rich remer Avatar answered Oct 25 '22 22:10

rich remer