0

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.

0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

7 Comments

I thought config file is optional,will try
Nope,doesnt help.
Or try debugging your code in devtool in chrome. Check what's the value of f before executing it.
It is an object ,has config and exports properties.
Thanks,guess module is something like a reserved name,it worked when I changed the name of the module.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.