I am trying to migrate my Javascript files to Typescript files, however I am stuck when I try to use the transpiled javascript file in html page and get the following error:
https://requirejs.org/docs/errors.html#notloaded
at makeError (require.min.js:1)
at Object.s [as require] (require.min.js:1)
at requirejs (require.min.js:1)
at helloworld.js:4
My Typescript file
import * as $ from "jquery";
export class Loading {
public showLoadingModal(msg?: string) {
if (msg === undefined) {
msg = "Loading ...";
}
$("#dialog1 label").html(msg);
//$('#pleaseWaitDialog').modal({ backdrop: 'static', keyboard: false });
}
public hideLoadingModal() {
// $('#pleaseWaitDialog').modal('hide');
}
public keepOpenLoadingModal() {
$("#dialog1").on("hide.bs.modal", function () {
return false;
});
this.showLoadingModal();
}
}
Transpiled Javascript file
"use strict";
exports.__esModule = true;
exports.Loading = void 0;
var $ = require("jquery");
var Loading = /** @class */ (function () {
function Loading() {
}
Loading.prototype.showLoadingModal = function (msg) {
if (msg === undefined) {
msg = "Loading ...";
}
$("#dialog1 label").html(msg);
//$('#dialog1').modal({ backdrop: 'static', keyboard: false });
};
Loading.prototype.hideLoadingModal = function () {
// $('#dialog1').modal('hide');
};
Loading.prototype.keepOpenLoadingModal = function () {
$("#dialog1").on("hide.bs.modal", function () {
return false;
});
this.showLoadingModal();
};
return Loading;
}());
exports.Loading = Loading;
I have loaded the Jquery from CDN like below
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We"
crossorigin="anonymous"
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
var exports = {};
</script>
<script src="helloworld.js"></script>
</head>
<body>
<h3 class="text-center mt-2 mb-2">Demo</h3>
</body>
</html>
I also tried loading the jquery with below code but no luck
var exports = {};
requirejs.config({
baseUrl: "/js/lib",
paths: {
jquery: "jquery.min",
},
});
requirejs(["jquery"], function (jquery) {
console.log(jquery); // OK
});
</script>```
Can you please help me resolve the error, I know this is very first step in my migration journey and I am badly stuck here, any help is much appreciated.