Reputation: 823
I created a script, and I want to use deno compile --unstable [src]
to make it into an executable, but when I try to run the executable it says permission denied.
My question is is there a way to create the executable with permission flags like you can deno install --flag [src]
.
Upvotes: 2
Views: 1400
Reputation: 22545
From Deno 1.7.0 on, the compile function has the same permission flags that we know from the run command.
Code that would need permissions (e.g. --allow-write
) when run as a script, needs the same permissions given to the compile command.
For example, consider this short script that creates a file and writes text into it:
const write = Deno.writeTextFile("./hello.txt", "Hello World!");
write.then(() => console.log("File written to ./hello.txt"));
Run as a script with --allow-write
:
> deno run --allow-write .\filewrite.ts
File written to ./hello.txt
Compiled without --allow-write
. The error message could be interpreted as if you need to apply the option to the created .exe, but in fact it needs to be applied during compilation:
>deno compile --unstable .\filewrite.ts
...Emit filewrite>.\filewrite.exe
error: PermissionDenied: write access to "./hello.txt", run again with the --allow-write flag
Compiled with the --allow-write flag:
>deno compile --unstable --allow-write .\filewrite.ts
...Emit filewrite>.\filewrite.exe
File written to ./hello.txt
The same is of course true for the --allow-read
and --allow-net
flags.
The previous Deno version (1.6.3) didn't have these compiler flags and behaved as if all permissions had been granted. See the older revision of this answer
Upvotes: 3