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

277
Views
"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
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!