TypeScript错误TS5014:位于0的JSON中出现意外的标记u [英] TypeScript error TS5014: Unexpected token u in JSON at position 0

查看:710
本文介绍了TypeScript错误TS5014:位于0的JSON中出现意外的标记u的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将.ts编译为.js

I am trying to compile a .ts to .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
        }
    }
]
}

当我尝试运行构建任务时,我收到以下错误

When I try to run the build task, I am getting the below error

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中添加了版本

What I am doing wrong? Please, note I have added the versions in package.json

推荐答案

在收到同事的建议并从这个链接中尝试一些内容后,我重新编写了这些任务.json如下,它现在有效。似乎命令以前有一些问题

After getting advice from collegues and trying something from this link, I re-write the tasks.json as below and it now worked. Seems the command has some problem previously

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {
        "taskName": "compile",
        "type": "shell",
        "command": "tsc -p tsconfig.json",
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "problemMatcher": []
    }
]
}

这篇关于TypeScript错误TS5014:位于0的JSON中出现意外的标记u的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆