0

I'm using requireJS. I have two files, with main app configuraction, functions:

app/main.js

define(["jquery", "jquery_migrate"], function() {
    return {
        bar: function() {
            console.log('test');
        }
    }
});

and with some events to fire up this function:

app/events.js

require(['main_app'], function(foo) { 
    $('body').on('click', function(e) {
        foo.bar();
        e.preventDefault();
    });
});

and this is routing file:

app.js

requirejs.config({
    "baseUrl": "js/libs",
    "paths": {
        "main_app":         "../app/main",
        // global
        "app":              "../app",
        "jquery":           "jquery/jquery",
        "jquery_migrate":   "jquery/jquery_migrate"
    }
});
requirejs([ "app/main", "app/events" ]);

I still have Uncaught Error: Script error for: main_app and no reponse from click event. Can anybody help? Much thx.

2 Answers 2

2

Get rid of the the main_app key

requirejs.config({
    "baseUrl": "js/libs",
    "paths": {
        //"main_app":         "../app/main", // I believe this is causing a conflict
        // global
        "app":              "../app", 
        "jquery":           "jquery/jquery",
        "jquery_migrate":   "jquery/jquery_migrate"
    }
});

app/events.js

require(['app/main'], function(foo) { 
    $('body').on('click', function(e) {
        foo.bar();
        e.preventDefault();
    });
});
Sign up to request clarification or add additional context in comments.

Comments

0

Because of this error Uncaught Error: Script error for: main_app, your scripts won't execute.

Chances are your require.config is not loaded or not pointing to the correct path. Verify in the Networks tabs what file is actually loaded and then fix it.

If the paths are correct, then you have a JS syntax error somewhere in your code.

1 Comment

all scripts loading corectly, also i don't see any syntax error :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.