【问题标题】:Trying to execute "npx typescript --init" "npm ERR! could not determine executable to run"尝试执行“npx typescript --init”“npm ERR!无法确定要运行的可执行文件”
【发布时间】:2021-10-21 19:34:09
【问题描述】:

错误npm ERR! could not determine executable to run是什么意思?

我正在尝试使用 typescript 和 yarn 初始化一个简单的 nodejs 应用程序。我以前从未真正使用过纱线。

我已经运行了以下命令: yarn init 成功创建了package.json npx typescript --init 给我上面的错误信息。

版本: 纱线 v1.22.11 npx 7.12.0

我已经运行了yarn add typescript,它给了我:

info Direct dependencies
└─ typescript@4.3.5
info All dependencies
└─ typescript@4.3.5

但是当我尝试typescript -v 我得到typescript: command not found

【问题讨论】:

  • 我不知道你想做什么,但是如果你想创建一个tsconfig.json文件,那么我使用的命令是tsc --init

标签: node.js typescript npm yarnpkg


【解决方案1】:

解决方法是使用命令npx tsc --init

我不知道为什么我关注的教程使用了npx typescript --init,但它对他们有用,对我无效。

【讨论】:

  • 这对我有用。
【解决方案2】:

JimmyTheCode's answer 上扩展,它可以工作,因为tsc 是一个只安装打字稿的虚拟包。

在不安装另一个软件包的情况下解决此问题的正确方法是使用npx 上的-p|--package 选项。从包中调用特定二进制文件时,此标志很有用。

npx --package typescript tsc --init
# OR
npx -p typescript tsc --init

您可以通过npx's documentation了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-21
    • 2012-09-25
    相关资源
    最近更新 更多