Running these "Install from source" instructions, I get an error:
error: Uncaught Error: %1 is not a valid Win32 application. (os error 193)
Specifically the instructions include:
deno task build
build
task is configured in deno.json
as:
"build": "deno run --allow-all --unstable './tasks/build.ts'",
build.ts
eventually runs code like this:await Deno.run({ cmd: ["./node_modules/.bin/esbuild"] }).status()
I use Windows machine, and the command "./node_modules/.bin/esbuild"
works from both my Windows cmd and my Git Bash.
I have deno --version
:
$ deno --version
deno 1.33.4 (release, x86_64-pc-windows-msvc)
v8 11.4.183.2
typescript 5.0.4
I saw Deno.run
is deprecated, so I used new Deno.Command(...)
instead, I still get the error.
I tried playing with certain CommandOptions to specify the cwd
and set windowsRawArguments
to true, but it doesn't work.
I tried checking other similar questions
shell=True
, but I don't think Deno has the equivalent optionEDIT
I understand the difference between the different commands. I understand how the esbuild.cmd file emulates the esbuild "shebang" line
node_modules
> .bin
> esbuild #This is for Unix, has shebang
> esbuild.cmd #This is for Windows
> esbuild.ps1
That doesn't explain why Deno can't run the esbuild
.
My Python can run the esbuild
, without needing to use esbuild.cmd
(notice I use shell=True
). Without shell=True
, I get the same error as with Deno. So maybe my question is better restated as, "how can I do the equivalent of Python's shell=True
in Deno?")
subprocess.call('"./node_modules/.bin/esbuild"', shell=True)
My Windows command line (after I open it) can run the esbuild
, without needing to use esbuild.cmd
(I have Git Bash installed, but see the screenshot, I am using Windows command prompt)
When I run cmd.exe "./node_modules/.bin/esbuild"
, it does not work, I get an error:
'"./node_modules/.bin/esbuild"' is not recognized as an internal or external command, operable program or batch file.
When I use Node instead of Deno, I get the same error:
const {spawn} = require('child_process');
const esbuild = spawn('"./node_modules/.bin/esbuild"', {shell:true});
esbuild.stderr.setEncoding('utf8');
esbuild.stderr.on('data',_=>console.error(_))
>> '"./node_modules/.bin/esbuild"' is not recognized as an internal or external command, operable program or batch file.
Ultimately I guess the workaround is "stop trying to behave like Linux, you're using Windows, accept that and just use the esbuild.cmd file"
But I'm still curious about why some languages/subprocesses can run the esbuild
(Python shell=True), but others cannot (cmd.exe run with args, Deno, Node with shell=True). It's small silly detail with lots of nuance, but maybe not significant enough to remain a question...
In this case, note the command I was trying to run:
new Deno.Command("./node_modules/.bin/esbuild").output()
Following the suggestion of this answer, I changed my command to use the esbuild.cmd
file. It worked, no error...
new Deno.Command("./node_modules/.bin/esbuild.cmd").output()
This suggestion wasn't obvious to me because my Windows command line was able to execute this:
"./node_modules/.bin/esbuild"
But my Deno.Command(...)
was not able to execute the above, until I changed the command to use the esbuild.cmd
instead. I'm not sure why...
EDIT
I tried to edit my answer to show why I think this is a workaround. It's a fine workaround, I should accept that I'm running Windows, so cmd
files are meant for me. But in my question I show how Python can run the esbuild
file directly, and so can Windows command prompt, so why not Deno? (or Node?).