Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing an external module in TS causes "ReferenceError: require is not defined"

Tags:

typescript

So when importing an external module like so

import GameObjects = module("GameObjects")

the outputed JS has this at the top of the file:

var GameObjects = require("./GameObjects")

but gives this error when run in chrome:> Uncaught ReferenceError: require is not defined

how do I get by this error?

like image 387
Nikos Avatar asked Dec 12 '12 10:12

Nikos


1 Answers

External modules require a module loader to be present. If you run this in your browser you have to take care of including a module loader yourself. Please take a look at require.js, it has all the documentation that's needed to get the module loader running.

like image 99
Valentin Avatar answered Nov 15 '22 05:11

Valentin