【问题标题】:'tsc' is not recognized as an internal or external command on Windows when installed globally全局安装时,“tsc”在 Windows 上不被识别为内部或外部命令
【发布时间】:2018-09-18 14:35:28
【问题描述】:

我在 StackOverflow 上看到了一堆 'tsc' is not recognized as an internal or external command 问题,但没有一个可以帮助我解决问题。

我已经在全球范围内安装了打字稿:

npm install -g typescript

C:\Users\<user_name>\AppData\Roaming\npm 目录中有tsctsc.cmd 文件。所以%AppData%\npm\tsc --version 命令有效。

我的用户路径中有C:\Users\<user_name>\AppData\Roaming\npm 目录。

更多,当我在任意目录中运行where tsc 命令时,我得到:

C:\Users\<user_name>\Desktop>where tsc
C:\Users\<user_name>\AppData\Roaming\npm\tsc
C:\Users\<user_name>\AppData\Roaming\npm\tsc.cmd

但是,当我尝试运行 tsc 时,我得到了:

C:\Users\<user_name>\Desktop>tsc
'tsc' is not recognized as an internal or external command,
operable program or batch file.

gruntuglifyjs 出现完全相同的问题。

【问题讨论】:

  • 试试这个 npx tsc ttest.ts

标签: node.js typescript tsc


【解决方案1】:

我设法解决了这个问题。

C:\Users\&lt;user_name&gt;\AppData\Roaming\npm 确实在用户的 PATH 变量中。我还有一个名为Path 的系统变量(是的,只是第一个字母是大写的)并且那里没有C:\Users\&lt;user_name&gt;\AppData\Roaming\npm

当我将它添加到系统的Path 时,它终于开始工作了。

不确定我的两个路径变量具有不同的名称(就大小写而言)是否可行。也不确定这种情况是否会导致问题。 如果有人能澄清这一点,我会很高兴。

【讨论】:

    【解决方案2】:

    尝试为 windows 安装 linux 控制台 cygwin 控制台。然后从该控制台运行命令 tsc,我知道它并没有太大变化,但有时我已经解决了该控制台的许多问题。

    https://www.cygwin.com/

    【讨论】:

    • 不需要,可以在cmdpowershell等运行
    猜你喜欢
    • 2018-12-13
    • 2018-03-23
    • 1970-01-01
    • 2020-09-05
    • 2012-02-03
    • 1970-01-01
    • 2018-04-16
    • 2021-09-15
    • 2021-02-08
    相关资源
    最近更新 更多