最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I get real errors with requirejs? - Stack Overflow

programmeradmin3浏览0评论

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 pletley vague error:

Error: script error
.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...

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 pletley vague error:

Error: script error
http://requirejs/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...

Share Improve this question edited May 23, 2017 at 12:30 CommunityBot 11 silver badge asked Oct 15, 2013 at 3:00 BrigandBrigand 86.3k20 gold badges167 silver badges173 bronze badges 5
  • 1 Their terrible error logging has bugged me for awhile. I really don't see why it can't say something like error loading script name blah/foo which was searched for at blah/foo.js – Adam Rackis Commented Oct 15, 2013 at 3:11
  • 1 Okay, I'll just use browserify. I wanted to give requirejs a try. Thanks – Brigand Commented Oct 15, 2013 at 3:48
  • 1 Can you and @AdamRackis elaborate on what errors you're missing? Load failures on modules themselves, or errors within the javascript of those modules? For the former, I get nice 404s in the console window, at least on latest Chrome and with RequireJS 2.1.8 – Steve P Commented Oct 15, 2013 at 14:27
  • @explunit, the problem is I didn't know what to be looking for. My IDE has AST analysis and it didn't find any errors in the code, or unresolvable paths. The RequireJS docs for "script error" say it's likely a syntax error or an uncaught error. It's not a 404, though. Anyway, if you want to post an answer I'll accept it. I've gone back to Browserify and everything's working now. I think I was missing a "new" in one of the files. – Brigand Commented Oct 15, 2013 at 15:21
  • Well, this is what that error means: requirejs/docs/errors.html#scripterror – Richard Knop Commented Oct 23, 2013 at 9:45
Add a ment  | 

1 Answer 1

Reset to default 6

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;
};
发布评论

评论列表(0)

  1. 暂无评论