I have been working on integrating Typescript support into Magento 2 to modernize it. Everything seems to compile correctly, but I am facing an issue with loading it.
My require-config.js file looks like this:
var config = {
deps: [
"web/js/app"
],
bundles: {
"web/js/app": [ "main", "moduleone", "moduletwo" ]
}
};
In my web/js/app.js file, I have the following Typescript code:
define("moduleone", ["require", "exports"], function (require, exports) {
// Code for ModuleOne
});
define("moduletwo", ["require", "exports"], function (require, exports) {
// Code for ModuleTwo
});
define("main", ["require", "exports", "moduleone", "moduletwo"], function (require, exports, Module1, Module2) {
// Main class code
});
When trying to load the module using the following script:
<script type="text/javascript">
require(['main'], function(Main) {
console.log(Main);
var app = new Main();
app.start();
});</script>
I encounter the error message:
Uncaught TypeError: Main is not a constructor
Would appreciate some assistance with this issue. Thank you!