Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda