Uğur KURT Uğur KURT - 4 years ago 86
Javascript Question

Requirejs function return error

My main.js file contains this code:

require(["module"],function(f){
f();
});


and my module.js file contains

define(function(){
var hasReturn = function(){
console.log("This returns");
}

return hasReturn;
});


But when I try to run this script my browser throws a type error,tells me f is not function.I ve searched for this but couldnt find anything helpful,sorry if posted before.

Answer Source

Do you have setting for libraries/modules base path? Try this

<script type="text/javascript">
require(
        {
            baseUrl: '@Url.Content("~/Content/js")',
            waitSeconds: 45,
            paths:
            {
               // dependencies here ex. jquery
            }
     });
</script>

Or explicitly put the path where the module located?

require(["path/mymodule"],function(f){
    f();
});

file : mymodule.js

Updated : I guess your problem is name of the module conflict somewhere else. Try to change the name of the module both file and in require. This will solve your problem. No need to add path if they both exists in same location

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download