How do I get real errors with requirejs?

2019-03-20 21:24发布

问题:

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...

回答1:

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;
};