【问题标题】:VS Code Run extension - no output shown from running programVS Code Run 扩展 - 运行程序没有显示输出
【发布时间】:2020-10-01 13:39:02
【问题描述】:

最近我尝试了 Deno,因为它支持原生 TypeScript,我认为将它用作“typescript runner”会很好。例如,在 Node 中您可以编写 node server.js,而在 Deno 中则为 deno run -A server.ts,所有这些都在代码运行器扩展中。

在 vscode settings.json 中:

"code-runner.executorMap": {    
    "javascript": "node",
    "typescript": "cd $dir && deno run -A $fileName"       
}

考虑以下 ts 文件“index.ts”:

const add = (a: number,b: number):number =>{
    console.log(a+b);
    return a+b;
}

add(1,2);

使用扩展运行时的输出:

[Running] deno run -A index.ts
[33m3[39m

[Done] exited with code=0 in 0.082 seconds

使用终端 cmd/powershell 时的输出:

C:\Users\Oliver\Desktop\DenoPJ>deno run -A index.ts
3

关于为什么它在终端内而不是在扩展内工作的任何想法?

【问题讨论】:

    标签: node.js typescript visual-studio-code deno vscode-code-runner


    【解决方案1】:

    我尝试过并且可以重现该问题。

    当您将“运行代码配置”下的设置更改为“在终端中运行”时

    然后使用 AltCtrlN 再次运行代码, VSCode 将切换到终端窗口,您应该会看到:

    PS C:\Users\jps\source\deno> cd "c:\Users\jps\source\deno\" ; if ($?) { deno run -A index.ts }
    3
    

    【讨论】:

      【解决方案2】:

      尝试在命令中添加标志(取决于您的应用程序操作):

      deno run --allow-net --allow-read --allow-write --allow-env index.ts
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-13
        • 2021-09-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-18
        相关资源
        最近更新 更多