You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下Deno调用esbuild报Win32应用错误的技术问询

解决Windows下Deno调用node_modules/.bin/esbuild的os error 193问题

Deno中Python shell=True的等效实现

要在Deno中实现类似Python shell=True的命令执行逻辑,需要显式调用系统shell来包裹目标命令,让shell自动处理脚本的解释和后缀匹配:

方案1:调用Windows cmd.exe

// 用cmd.exe /c执行命令,自动识别并处理esbuild.cmd
await new Deno.Command("cmd.exe", {
  args: ["/c", "./node_modules/.bin/esbuild"],
  stdin: "inherit",
  stdout: "inherit",
  stderr: "inherit"
}).spawn().status();

方案2:调用Git Bash(如果已安装)

// 用bash.exe直接执行Unix脚本
await new Deno.Command("bash.exe", {
  args: ["./node_modules/.bin/esbuild"],
  stdin: "inherit",
  stdout: "inherit",
  stderr: "inherit"
}).spawn().status();

差异原因解析

  1. Python shell=True的行为:当设置shell=True时,Python会委托系统默认shell(Windows下为cmd.exe)执行命令。shell会自动处理以下逻辑:

    • 查找并优先执行同名的.cmd/.bat批处理文件(比如esbuild.cmd)
    • 若遇到无后缀的文本脚本,会尝试调用合适的解释器(如Git Bash的bash)执行
  2. Deno/Node的默认行为:Deno的Deno.run/Deno.Command、Node的spawn/execFile默认是直接调用文件,不经过shell解析。在Windows下,系统会把无后缀的./node_modules/.bin/esbuild(Unix脚本)当成Win32可执行文件,而该文件实际是文本格式,因此抛出os error 193(不是有效的Win32应用)。

  3. 临时方案的原理:直接指定esbuild.cmd时,系统能识别这是Windows批处理文件,会调用cmd.exe执行它,因此可以正常运行。

内容的提问来源于stack exchange,提问作者Nate Anderson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 20:13:17