Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

286
Vistas
"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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda