I'm using RequireJS and when I define a new module using the function "define" I see the dependencies were resolved but the objects are not the modules I defined.
All the modules are defined in AMD format, setting a name, array of dependencies and a function. The exportation is done by return an object.
The dependencies resolved by "define" have these properties: exports, id, packaged, and uri. If I then call require function the dependencies are set correctly.
UPDATE: I created a test example with the described issue
HTML:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Test</title>
<script src="/Scripts/require.js" data-main="../Scripts/main"></script>
<script src="/Scripts/module.js"></script>
</head>
<body>
<div>
</div>
</body>
</html>
main.js:
require(["module"], function (module) {
module.test();
});
module.js:
define([], function () {
function test() {
return "a";
}
return {
test: test
};
});
Console: Uncaught TypeError: module.test is not a function
This happens because module is not resolved to the real module but to an object with properties:
-config { arguments: null, caller: null, length: 0, name: "config" }
-exports { id: "@r5", uri: "../Scripts/@r5.js" }
Setting a module name in the define function has the same result.
NOTE: in the example there was an issue detected by @Louis. A module cannot be named "module". This helped me fixed the example but didn't fix my real issue. Below I describe the solution.
SOLUTION:
My issue was related to a library called Ace (HTML editor). This is the link that helped me solve it: https://github.com/josdejong/jsoneditor/issues/173
bConfig
at one place andbuilderConfiguration
at another? Are they the same? – dbfdefine
should not, just becauserequire
does. You have to understand howrequire.js
locates modules by settings it'spath
, either absolute or relative. If you do not receive a failure thatbConfig
module could not be loaded, or normalized to a module according to yourrequire.config
settings, then the only problem I can think of is that you have multiplebConfig.js
files in your project directory. Doesn't make sense otherwise. – dbf