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

前端 未结 2 502
栀梦
栀梦 2020-12-11 19:47

So when importing an external module like so

import GameObjects = module(\"GameObjects\")

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

相关标签:
2条回答
  • 2020-12-11 20:14

    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.

    0 讨论(0)
  • 2020-12-11 20:24

    If you want to use the built-in Microsoft solution, then replace your import with Triple Slashes.

    So instead of import GameObjects = module("GameObjects"), you do /// <reference path="./Gameobjects.ts" /> at the top of the file.

    0 讨论(0)
提交回复
热议问题