【问题标题】:Typescript ///<reference path=“…”> and "Uncaught ReferenceError: exports is not defined"Typescript ///<reference path=“…”> 和“未捕获的 ReferenceError:未定义导出”
【发布时间】:2017-06-20 09:10:07
【问题描述】:

我写了以下文件:

ma​​in.ts:

///<reference path="./external.ts"/>

hello();

external.ts

var hello = function() {
    console.log("hello");
}

在 html 文件中我放置了语句:

 <script src="external.js" type="text/javascript"></script>
 <script src="main.js" type="text/javascript"></script>

当我用 html 文件打开浏览器时,我预计会调用函数“hello”,但没有。我得到了错误:

未捕获的引用错误:未定义导出

这个问题和我之前发的问题差不多:Typescript ///<reference path="...">: why doesn't it work for me?

但这一次它处理的是浏览器中的代码,而不是服务器端的代码(如上一个问题)。

【问题讨论】:

  • exports is not defined 听起来像是语法错误,我会仔细检查并确保无论您在哪里导出它都显示 export 而不是 exports

标签: typescript


【解决方案1】:

具有上述内容的两个文件工作正常。

也就是说错误很可能是由文件中的附加代码引起的,如exportimport 行。这使文件成为一个模块,您需要使用模块捆绑器(例如 webpack)在浏览器中使用生成的 JS。

更多

【讨论】:

猜你喜欢
  • 2019-02-28
  • 1970-01-01
  • 2017-07-27
  • 2018-02-20
  • 1970-01-01
  • 2017-08-19
  • 2017-09-20
  • 1970-01-01
  • 2018-01-21
相关资源
最近更新 更多