无法在vs代码中编译Typescript:错误TS5007

stt*_*106 14 typescript visual-studio-code

我刚刚安装了vs code v1(最新版本)和typescript v1.8.10(最新版本).我遵循了vs代码网站的确切指令但是无法获得vs代码来构建最简单的typescript文件,尽管我可以通过在git bash中运行tsc命令来手动构建它.vs代码的输出是:

error TS5007: Cannot resolve referenced file: '.'.
error TS5023: Unknown option 'p'
Use the '--help' flag to see options.
Run Code Online (Sandbox Code Playgroud)

这是我的helloworld.ts文件,真的不能简单:

class Greet {
    private _message : string;
    constructor(message : string) {
        this._message = message;
    }
    Say = () => console.log(this._message);
}

var g = new Greet('hello typescript!');
g.Say();
Run Code Online (Sandbox Code Playgroud)

这是我的tasks.json文件:

{
    // See http://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "tsc",
    "isShellCommand": true,
    "args": ["-p", "."],
    "showOutput": "silent",
    "problemMatcher": "$tsc"
}
Run Code Online (Sandbox Code Playgroud)

和tsconfig.json:

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "sourceMap": true
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 26

也许它可以帮助提到(VS代码,错误,TS5023)未知的编译器选项'p'

打开您的环境设置并从系统PATH变量中删除旧的Typescript.我的是C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\.

  1. 按住Windows按钮并按下PauseBreak键
  2. 高级系统设置
  3. 环境变量
  4. 在"系统"面板(Windows 10中的底部)中,选择Path变量并单击Edit
  5. 查找并突出显示C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\文本中的旧版本,将其删除.按"确定"三次.
  6. 重启VS代码


Dev*_*Zen 8

我在vs代码中遇到了这个错误.Box [Windows 08,VS Code]

 error TS5007: Cannot resolve referenced file: '.'.
   error TS5023: Unknown option 'p'
   Use the '--help' flag to see options.
Run Code Online (Sandbox Code Playgroud)

  1. C:\Program Files (x86)\Microsoft SDKs\TypeScript
  2. 如果您同时拥有1.0和1.8版本,则重命名或删除1.0.如果您没有1.8版本,请从官方下载页面安装新的打字稿版本.我安装了Visual Studio 2013

然后它奏效了.

注意: - 这个答案建议做同样的事情.我写这个答案是为了明确地显示所有步骤.此外,我认为社区在回答时不鼓励仅链接文章,因为链接可能已经死亡.

  • 作为一般提示,请不要参考"上述答案".它高于你的*现在*,因为它有更高的分数,但这可能会改变.而其他人可能会发布更多答案,然后很难理解你的意思.解决方案是添加一个链接. (2认同)