【发布时间】:2018-01-29 02:52:16
【问题描述】:
我正在尝试将 .ts 编译为 .js
我有tsconfig.json 如下
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"outFile": "build/test.js"
},
"exclude": [
"node_modules"
]
}
下面是我的package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"tsc": "^1.20150623.0",
"typescript": "^2.4.2"
}
}
自动生成的tasks.json 如下所示
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": [
"$tsc"
],
"group": {
"kind": "build",
"isDefault": true
}
}]
}
当我尝试运行构建任务时,出现以下错误
Executing task: <myprojloc>\node_modules\.bin\tsc.cmd -p "<myprojloc>\tsconfig.json" <
error TS5014: Failed to parse file '<myprojloc>/tsconfig.json/tsconfig.json': Unexpected token u in JSON at position 0.
Terminal will be reused by tasks, press any key to close it.
我做错了什么?请注意我在package.json中添加了版本
【问题讨论】:
-
也许您在文件开头有 BOM [en.wikipedia.org/wiki/Byte_order_mark]。
-
我也保存了没有 BOM 的文件。还是一样的@Felix
-
还在 tsconfig.json 中添加了 "emitBOM": false。没有区别
标签: javascript json typescript