简体   繁体   中英

RequireJS main require call back never invoked

I've tried this post's advice to no avail. No matter what I do, RequireJS's primary callback is never fired. Here's my dependency graph:

/module/main.js
    -- /module/mainController.js
        --/vendor/preloadjs
        --/module/itemController.js
        --/module/router.js
            --/vendor/crossroads.js
                --/vendor/signals.js
            --/vendor/hasher.js
                --/vendor/signals.js
require.config({
    baseUrl: "script/module",
    paths: {
        signals: "vendor/signals"
    }
});

require(["main", function(){
    console.log("main function!");
}]);

The "main" module makes use of js-signals, and actually gets invoked. In fact the entire dependency tree is loaded (confirmed via the web inspector). I have a single entry point for the application. All modules start up and actually run fine. You'd think that if the main application callback doesn't run that one or all of its dependencies would have failed.

I'm sure there is some stupid reason I'm not kicking off the primary require's callback. For the record I've tried using the requirejs() method and get the same results.

No files have code in them except for dependencies and console.logs.

Does anyone have any ideas for what I'm doing wrong?

I'll answer my own silliness. The problem is right there in the source. I'm using Angular module injection syntax, and passing the callback as part of the dependency array. Oops. It needs to be the second argument!

Long story short, the code is right, but this is the change:

require.config({
    baseUrl: "script/module",
    paths: {
        signals: "vendor/signals"
    }
});

require(["main"], function(){
    console.log("main function!");
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM