tsc 不被识别为内部或外部命令 [英] tsc is not recognized as internal or external command

查看:32
本文介绍了tsc 不被识别为内部或外部命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 VSCode 0.10.6 更新到 0.10.8,并且第一次尝试使用 Typescript.不幸的是,当我告诉 VSCode 构建时,出现错误:

I updated from VSCode 0.10.6 to 0.10.8, and tried using Typescript for the first time. Unfortunately I when I tell VSCode to build, I get the error:

tsc 不是被识别为内部或外部命令...

tsc is not a recognized as an internal or external command...

以下是相关详细信息:

  • 我创建了一个全新的HelloWorld"项目 根据 VS Code 说明.这包括:
    • 我为一个新的 package.json 运行了 npm init
    • 我运行 npm i --save-dev typescript 因为我想要本地安装,而不是全局安装.
    • 我创建了一个 launch.json 来定义一个 node.js 项目.
    • 我创建了 tasks.json 文件,并为 tsc 指定了设置.
    • I created a fresh "HelloWorld" project according to VS Code instructions. This included:
      • I ran npm init for a new package.json
      • I ran npm i --save-dev typescript because I want a local install, rather than a global install.
      • I created a launch.json to define a node.js project.
      • I created the tasks.json file, with prescribed settings for tsc.

      我已经重新启动了 VSCode(几次).我错过了什么?还必须做什么?

      I have restarted VSCode (several times). What am I missing? What more must be done?

      我尝试了@zlumer 提供的解决方案.它成功地使打字稿编译器运行,但随后导致出现数千个错误.为了解决这个问题,我还必须调整我的 tsconfig.json 以排除 node_modules 文件夹:

      I tried the solution offered by @zlumer. It succeeded in making the typescript compiler run, but then it caused thousands of errors to appear. To fix that, I also had to adjust my tsconfig.json to exclude the node_modules folder:

      "exclude": [
          "node_modules"
      ]
      

      推荐答案

      问题是 tsc 如果在本地安装,则不在您的 PATH 中.

      The problem is that tsc is not in your PATH if installed locally.

      您应该修改您的 .vscode/tasks.json 以包含 tsc 的完整路径.

      You should modify your .vscode/tasks.json to include full path to tsc.

      要更改的行可能等于 "command": "tsc".

      The line to change is probably equal to "command": "tsc".

      您应该将其更改为 "command": "node" 并将以下内容添加到您的参数中: "args": ["${workspaceRoot}\node_modules\typescript\bin\tsc"](在 Windows 上).

      You should change it to "command": "node" and add the following to your args: "args": ["${workspaceRoot}\node_modules\typescript\bin\tsc"] (on Windows).

      这将指示 VSCode:

      This will instruct VSCode to:

      1. 运行 NodeJS(它应该全局安装).
      2. 将本地 Typescript 安装作为要运行的脚本.

      (这几乎就是 tsc 可执行文件所做的)

      (that's pretty much what tsc executable does)

      您确定不想全局安装 Typescript 吗?它应该会让事情变得更容易,尤其是当您刚开始使用它时.

      Are you sure you don't want to install Typescript globally? It should make things easier, especially if you're just starting to use it.

      这篇关于tsc 不被识别为内部或外部命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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