Javascript 使用Visual Studio 2017将Typescript传输到ES5-未定义导出
我正在尝试使用Visual Studio 2017将Typescript集成到现有的ASP.NET MVC项目中。据我所知,人们通常会使用任务运行程序和/或Webpack等捆绑程序将“较新”的JS传输到ES5中,但似乎Visual Studio 2017应该为您处理传输 但是,在浏览器中运行网站时,我收到以下错误:Javascript 使用Visual Studio 2017将Typescript传输到ES5-未定义导出,javascript,visual-studio,ecmascript-6,es6-modules,Javascript,Visual Studio,Ecmascript 6,Es6 Modules,我正在尝试使用Visual Studio 2017将Typescript集成到现有的ASP.NET MVC项目中。据我所知,人们通常会使用任务运行程序和/或Webpack等捆绑程序将“较新”的JS传输到ES5中,但似乎Visual Studio 2017应该为您处理传输 但是,在浏览器中运行网站时,我收到以下错误: ReferenceError: exports is not defined[Learn More] 我当前的.tsconfig如下所示: { "compileOnSave
ReferenceError: exports is not defined[Learn More]
我当前的.tsconfig如下所示:
{
"compileOnSave": true,
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"module": "commonjs",
"outDir": "./Scripts/out/",
"rootDir": "./Scripts/src"
},
"exclude": [
"node_modules",
"wwwroot",
"outDir",
"./Scripts/out/"
],
"lib": [
"es2016",
"dom",
"es5"
]
}
我曾尝试删除“module”:“commonjs”
行,并如前所述添加es5库,但收到了相同的错误
应用程序滑块是我写的一个模块;hyperform是通过npm安装的。两者都是默认导出
import hyperform from "hyperform";
import AppSlider from "./app-slider";
let appSlider = new AppSlider(null);
let $hyperForm = hyperform("window");
let form: HTMLFormElement = document.getElementsByTagName("form")[0];
let prevButton: HTMLButtonElement = <HTMLButtonElement>document.getElementById("prev");
let nextButton: HTMLButtonElement = <HTMLButtonElement>document.getElementById("next");
prevButton.addEventListener("click", (e) => {
appSlider.showPrev();
});
nextButton.addEventListener("click", (e) => {
e.preventDefault();
if (form.checkValidity()) {
appSlider.showNext();
}
});
如果将“模块”选项更改为es6,则会出现不同的错误:
SyntaxError: import declarations may only appear at top level of a module
我使用的是TypeScript 2.5。如有任何建议,将不胜感激。谢谢。看起来您的
.tsconfig
文件未被解析-请将其重命名为tsconfig.json
?抱歉,这是我的错误。文件命名正确(tsconfig.json);我只是把我的问题的名字弄错了。谢谢。我也有这个问题。根据您链接到的qn和我的理解,一旦传输成功,那么tsconfig.json
就不再相关了。因为你和我都有一个运行时错误。在我看来,问题在于运行时没有包含CommonJS
。您找到解决方案了吗
SyntaxError: import declarations may only appear at top level of a module