D
Deno

help

Deno compile with "--no-terminal" don't work

IInplex-sys1/30/2024
I'm trying to compile a very simple file named main.ts
await Deno.writeTextFile('test.txt', 'Hello World');
await Deno.writeTextFile('test.txt', 'Hello World');
The problem is that after compiling and running the executable, it's doesn't work, it's showing nothing, but when i try to run the binary from a terminal it work. PS> deno compile --no-terminal -A main.ts Version: v8 12.1.285.6 typescript 5.3.3
DAHDeno AI Helper1/30/2024
The --no-terminal flag for deno compile is designed to prevent a terminal window from being opened when the compiled binary is run on Windows. This flag does not affect the functionality of your code; it only affects how the binary is executed in terms of terminal interaction. If your compiled binary is not working as expected when not run from a terminal, it could be due to a variety of reasons unrelated to the --no-terminal flag. Here are a few steps you can take to debug the issue: 1. Check Permissions: Ensure that the compiled binary has the necessary permissions to perform file operations. Since you are using the -A flag, this should grant all permissions, but it's still worth verifying. 2. Check File Paths: When running the binary outside of a terminal, the current working directory might be different. Make sure that the path to 'test.txt' is accessible from wherever the binary is being executed. 3. Error Handling: Modify your main.ts to include error handling to catch any exceptions that might occur during file writing. This can help identify if there's an issue with the file operation itself.
try {
await Deno.writeTextFile('test.txt', 'Hello World');
console.log('File written successfully');
} catch (error) {
console.error('Error writing file:', error);
}
try {
await Deno.writeTextFile('test.txt', 'Hello World');
console.log('File written successfully');
} catch (error) {
console.error('Error writing file:', error);
}
4. Logging: Add console logs before and after the file operation to see if the code is being executed at all when the binary is run outside of a terminal. 5. Check the Version: Make sure you are using a version of Deno that supports the --no-terminal flag. According to the documentation, this feature was introduced in Deno 1.36. You can check your Deno version with deno --version. If after these steps the issue still persists, you may want to compile
DAHDeno AI Helper1/30/2024
the binary without the --no-terminal flag and run it from a terminal to see if any error messages are displayed. This can provide further insight into what might be going wrong. Remember that when running the compiled binary outside of a terminal, you won't see console logs or errors unless you have a way to capture stdout and stderr. If the file 'test.txt' is not being created, it suggests that the binary is either not running at all, not running to completion, or encountering an error that prevents the file operation from succeeding.
LLeokuma1/30/2024

Looking for more? Join the community!