这不是您正在寻找的 tsc 命令

Bjö*_*rth 52 npm typescript tsc

当我tsc在终端中运行时(无论在哪里)我都会返回:

$ npx tsc --version

                This is not the tsc command you are looking for


To get access to the TypeScript compiler, tsc, from the command line either:

- Use npm install typescript to first add TypeScript to your project before using npx
- Use yarn to avoid accidentally running code from un-installed packages
Run Code Online (Sandbox Code Playgroud)

据我所知,我没有在全球范围内安装 TypeScript,所以我期望它找不到tsc.

小智 70

我的问题是我安装了tsc软件包而不是正确的typescript. 来自https://www.npmjs.com/package/tsc

用于typescript访问tscCLI 命令。

修复方法是:

npm uninstall tsc
npm install -D typescript
Run Code Online (Sandbox Code Playgroud)

像这样的命令npx tsc --version仍然会运行,因为typescript提供了tsc可执行文件。

  • 是的..你需要安装`typescript`包而不是`tsc` (5认同)
  • 修复实际上是“npm uninstall tsc”,然后是“npm install typescript”(即使之前安装过,因为在“tsc”卸载期间,无论安装哪个包,文件“node_modules/.bin/tsc”都会被删除)。 (2认同)

Vin*_*hah 26

在我的 Mac 上,这解决了这个问题:

npm uninstall -g typescript
npm install -g typescript
Run Code Online (Sandbox Code Playgroud)

当我闲逛试图开始时,我做了这样的事情:

npm install -g tsc   #bad, don't do this
Run Code Online (Sandbox Code Playgroud)

这搞砸了我的安装。


Viv*_*jan 9

没有什么可做的,因为这是一个非常简单的问题。转到已安装节点包的 VS Code 文件夹。例如,在我的系统中,它是:

C:\Users\vivekranjan\AppData\Roaming\npm

首先,您会注意到 tscServer 和 tsc 文件都没有创建。因此,首先删除所有 tsc 文件,然后转到 VS Code 并卸载 typeScript,如下所示:

npm uninstall typescript
Run Code Online (Sandbox Code Playgroud)

然后再次安装打字稿,如下所示:

npm install -g typescript
Run Code Online (Sandbox Code Playgroud)


Rah*_*pta 7

如果您收到tsc 命令错误,只需在终端上运行它

 npm install -g typescript --force
Run Code Online (Sandbox Code Playgroud)


Ger*_*erd 6

tsc模块已弃用!如果您需要 tsc,您只需要typescript 模块!

通过以下方式安装打字稿模块:

npm install -D typescript
Run Code Online (Sandbox Code Playgroud)


小智 5

这为我解决了这个问题:

npm uninstall typescript
npm uninstall tsc #local tsc package
npm install typescript -g
Run Code Online (Sandbox Code Playgroud)


Bjö*_*rth 4

我错误地安装了旧的 typescript 编译器https://www.npmjs.com/package/tsc 。

运行where.exe tsc以找出 @siddharth 建议的我实际运行的内容让我发现了问题