这不是您要找的 tsc 命令

问题描述 投票:0回答:14

当我在终端中运行

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

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

tsc

typescript npm tsc
14个回答
58
投票

我的问题是我安装了

tsc
软件包而不是正确的
typescript
。来自 https://www.npmjs.com/package/tsc:

使用

typescript
访问
tsc
CLI 命令。

修复方法是:

npm uninstall tsc
npm install -D typescript

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


22
投票

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

npm uninstall -g typescript
npm install -g typescript

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

npm install -g tsc   #bad, don't do this

这搞砸了我的安装。


8
投票

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

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

首先您会注意到 tscServer 和 tsc 文件都没有创建。所以首先删除所有的tsc文件,然后进入vs code并像这样卸载typeScript:

npm uninstall typescript

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

npm install -g typescript

6
投票

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

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

npm install -D typescript

5
投票

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

运行

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


5
投票

这解决了我的问题:

npm uninstall typescript
npm uninstall tsc #local tsc package
npm install typescript -g

2
投票

由于

typescript
已经作为
devDependency
和全局安装,对我来说,解决方案是更新
package.json
脚本:

之前:

{
  "scripts": {
    "build": "pnpx tsc ..."
  }
}

之后:

{
  "scripts": {
    "build": "tsc ..."
  }
}

也许其他人都知道

p/npx
中不需要
scripts
,但我不知道。

希望这对某人有帮助。


0
投票

尝试使用巧克力管理器进行打字稿安装 https://community.chocolatey.org/packages/typescript

choco install typescript

0
投票

如果使用 Volta 或类似的版本管理器,你可以这样做

npm remove -g typescript tic
pnpm remove -g typescript (if using pnpm)

并使用您选择的节点包管理器(全局)再次安装它!


0
投票

tsc 是

typescript/bin/tsc
,所以必须先
uninstall tsc
。 [1] https://i.stack.imgur.com/mUK0o.png


0
投票

在我的 Mac 中,只有在命令中添加“force”标志后才起作用:

npm uninstall -g typescript --force
npm install -g typescript --force

0
投票

转到

tsc.cmd
tsc.ps1
路径
看起来像这样

node_module
  typescript // remove this
  other...
tsc.cmd // remove this
other...

然后

npm install -g typescript@latest

0
投票
  1. 首次运行
    npm uninstall tsc
    ,它将删除所有.bin/tcs文件夹。
  2. 然后运行
    npm install typescript
    ,它将解决问题。

0
投票

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

 npm install -g typescript --force

© www.soinside.com 2019 - 2024. All rights reserved.