VisualStudio 2015中的打字稿设置出现错误:“未定义导出”。如何正确设置?

时间:2019-07-19 06:40:07

标签: javascript typescript tsconfig

我只是从打字稿开始,我正在通过打字稿进行导出导入

但是当我开始时,我在导出时遇到了错误,

Object.defineProperty(exports, "__esModule", { value: true });

错误是

  

未捕获的ReferenceError:未定义导出

一些Google之后,我经历了one solution

但根据该答案,我的项目应包含tsconfig.json, common.js

但是我没有这些

这是我的项目的屏幕截图

enter image description here

我该怎么办?

1 个答案:

答案 0 :(得分:0)

module.exports或更短的版本exports是仅存在于Node.js中的对象

尝试在浏览器中使用该变量将为您提供Uncaught reference error: exports is not defined

Node.js documentation reference for the exports shortcut

您应在项目中添加tsconfig.json,例如,将module设置为es6

您的设置可能默认为“ commonjs”,它期望您有一个exports对象,而该对象在浏览器中没有。看看here以获得更多的阅读内容。