【问题标题】:How to fix 'tsc: command not found'如何修复“tsc:找不到命令”
【发布时间】:2023-03-19 23:40:02
【问题描述】:

我目前正在尝试第一次在我的机器上安装 typescript。安装节点后,我运行以下命令:

sudo npm -g install typescript

这会产生似乎是积极的安装消息

/Users/mac/.npm-global/bin/tsc -> /Users/mac/.npm-global/lib/node_modules/typescript/bin/tsc /Users/mac/.npm-global/bin/tsserver -> /Users/mac/.npm-global/lib/node_modules/typescript/bin/tsserver + typescript@3.4.4 在 0.924 秒内更新了 1 个包

在此之后,我检查安装是否成功但正在运行 tsc --version 并收到以下错误:

tsc: command not found

来自我尝试过的另一个线程:

重启终端 重新启动机器 重新安装 nodejs + 然后运行sudo npm install typescript -g

我还尝试使用以下行更新我的 bash 配置文件:

export PATH="$PATH:"/Users/mac/.npm-global/lib/node_modules/typescript/bin/tsc"";

我不确定 typescript 是否位于我列出的位置。有没有办法确认?

任何帮助将不胜感激。

【问题讨论】:

  • I have also tried updating my bash profile with the following line 你应该将路径添加到 bin 目录,而不是可执行文件本身。
  • 非常感谢您非常及时和乐于助人的回复。事实上,这就是问题所在。将我的 bash 配置文件更改为 /Users/mac/.npm-global/lib/node_modules/typescript/bin 立即解决了这个问题。
  • @tkausl:您可以将其发布为答案——或者问题应该关闭或删除。

标签: typescript npm command-line


【解决方案1】:

以下问题很容易解决。从您的终端打开您的 bash 个人资料:

open ~/.bash_profile

编辑您的路径以指向 bin 而不是可执行文件(您的路径可能会有所不同,请参阅安装后的路径):

/Users/mac/.npm-global/lib/node_modules/typescript/bin/

保存并关闭您的文件。

重新加载您的 bash 个人资料:

source ~/.bash_profile

通过检查版本确认一切正常:

tsc -v

【讨论】:

    【解决方案2】:

    (2020) 这对我有帮助 npx tsc app.ts

    【讨论】:

      【解决方案3】:

      也许这对你有帮助

      第一种

      npm bin -g
      

      将上述命令的执行结果添加到你的PATH中。

      export PATH=""
      

      希望这可能有助于解决您的问题,如果没有,请告诉我。

      【讨论】:

        猜你喜欢
        • 2019-04-19
        • 2023-03-29
        • 2021-11-17
        • 2019-03-26
        • 2020-02-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多