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

289
Visualizações
"Uncaught ReferenceError: exports is not defined"

SO is full of answers to this and they are all very consistent and they are all not working for me, so I'm missing something blindingly obvious.

Even when I tried to give up and use the hack of sticking <script>var exports = {};</script> before the call to require.js, I get "Uncaught Error: Module name "src/functions" has not been loaded yet for context: _. Use require([])"

Here's my minimal non-working example that seems most consistent w/ the other answers. I've also tried sticking "type": "module" everywhere I could think of.

What am I missing?

lib/
  - require.js
node-modules/
functions/
  - functions.ts
package-lock.json
package.json
test.html
test.ts
tsconfig.json

src/functions.ts:

export function consoleLog(msg: string): void {
    console.log(msg);
};

package.json:

{
  "devDependencies": {
    "typescript": "^4.7.4"
  }
}

test.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>test</title>
</head>
<body>
    <script src="lib/require.js", data-main="test"></script>
</body>
</html>

test.ts:

import { consoleLog } from "./src/functions";

function main(): void {
    consoleLog("foo");
}

main();

tsconfig.json:

{
    "compilerOptions": {
        "target": "es6",
        "module": "amd",
        "moduleResolution": "node",
        "esModuleInterop": true
    },
    "resolveJsonModule": true
}
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