0
0
DenoHow-ToBeginner ยท 3 min read

How to Create Executable in Deno: Simple Steps

To create an executable in deno, use the deno compile command followed by your script file. This bundles your code and Deno runtime into a single executable file you can run without installing Deno.
๐Ÿ“

Syntax

The basic syntax to create an executable in Deno is:

  • deno compile [options] script.ts
  • --output <file>: Specify the output executable file name.
  • --target <platform>: Choose the platform (e.g., x86_64-unknown-linux-gnu, x86_64-pc-windows-msvc, x86_64-apple-darwin).

This command bundles your script and Deno runtime into one executable.

bash
deno compile --output myapp script.ts
๐Ÿ’ป

Example

This example shows how to create a simple executable from a Deno script that prints a greeting.

typescript
console.log("Hello from Deno executable!");
Output
Hello from Deno executable!
โš ๏ธ

Common Pitfalls

Common mistakes when creating executables in Deno include:

  • Not specifying the --output option, which defaults to the script name without extension.
  • Forgetting to set the correct --target for your platform, causing the executable to not run on your OS.
  • Using unstable Deno APIs without --unstable flag during compile.
  • Expecting dynamic imports or permissions to work without proper flags.
bash
deno compile script.ts

# Correct way:
deno compile --output myapp --target x86_64-apple-darwin script.ts
๐Ÿ“Š

Quick Reference

OptionDescription
--output Set the name of the output executable file
--target Specify the target platform for the executable
--unstableEnable unstable APIs during compilation
--allow-netAllow network access if your script needs it
--allow-readAllow file system read access if needed
โœ…

Key Takeaways

Use deno compile to bundle your script and runtime into one executable.
Always specify --output to name your executable file clearly.
Set the correct --target platform to ensure compatibility.
Add necessary permission flags like --allow-net or --allow-read if your script requires them.
Use --unstable flag if your code uses unstable Deno APIs.