Why require.js keep giving me script error without reason?
I'm using require.js right now, I'm using amd and let typescript help me to put all compiled file into one File named 'index.js', but I'm stopped by ScriptError:
Uncaught Error: Script error for "main"
https://requirejs.org/docs/errors.html#scripterror
at makeError (require.js:168:17)
at HTMLScriptElement.onScriptError (require.js:1738:36)
In require.js docs, they said if script error happens, usually means there is a syntax error, but I'm pretty sure there's no syntax error, and the error report does not have anymore details there.
main.ts, and there's no syntax error:
import { greet } from "./greet";
export function mainmethod() {
greet("Safari");
}
greet.ts:
export function greet(message: string): void {
console.log("Hello, " + message);
}
index.html, and load modules:
<html>
<canvas id = "canvas" width = "1050" height = "625" class = "MainCanvas"> </canvas>
<script data-main = "script/index" src = "script/require.js"> </script>
<script>
require(["main"], function(main) {
main.mainmethod();
});
</script>
</html>
structure is like this:
index.html
- script
- index.js
- require.js
- sourcecode
- main.ts
- greet.ts
- resources
ps: typescript will put them into small amd module like this:
define("greet", ["require", "exports"], function (require, exports) {
exports.greet = void 0;
function greet() {
console.log("Hello, " + message);
}
exports.greet = greet;
}
define("main", ["require", "exports", "greet"], function (require, exports, greet_1) {
exports.mainmethod = void 0;
function mainmethod() {
greet_1.greet("Safari");
}
exports.mainmethod = mainmethod;
}