在 Visual Studio 中编译 TypeScript 时出现错误“意外的标记...”
我正在使用 Visual Studio 2013 更新 5 开发一个大型复杂的 Node 项目。我安装了 tsc 版本 1.8.5,并且在系统中找不到任何其他版本的引用。当我在命令行使用 "tsc --module commonjs" 编译时,程序可以干净地编译通过。
当我在 Visual Studio 中编译时,我收到错误
Build: Unexpected token; 'module, class, interface, enum, import or statement expected'
被标记的文件是 express.d.ts。
这阻止我运行调试器,尽管我可以在命令行上编译。是不是 VS 配置有问题?
詹姆斯
答案#1
鉴于有效的命令行,我敢打赌你需要修改你的 tsconfg.json
下面的重要部分显然是 "module": "commonjs"
这是一个完整的“标准” tsconfig 文件,用于 Typings v1.0.0 或更高版本。
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"pretty": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true
},
"exclude": [
"node_modules",
"typings/index.d.ts",
"typings/modules"
],
"compileOnSave": false
}答案#2
右键单击项目并选择“属性”。在 Typescript 选项卡中,选择正确的模块系统(这将添加正确的编译器标志)
