Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
Why require.js keep giving me script error without reason?

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;
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!