babakfp
babakfpโ€ข2mo ago

Deno Oak doesnt work when compiled to `.exe`

Hi ๐Ÿ‘‹ I have this example from Deno site and when compile it to .exe and run it, I get the longs in the console of the .exe.
const port = 8080

const handler = (request: Request): Response => {
const body = `Your user-agent is:\n\n${
request.headers.get("user-agent") ?? "Unknown"
}`

return new Response(body, { status: 200 })
}

console.log(`HTTP server running. Access it at: http://localhost:8080/`)
Deno.serve({ port }, handler)
const port = 8080

const handler = (request: Request): Response => {
const body = `Your user-agent is:\n\n${
request.headers.get("user-agent") ?? "Unknown"
}`

return new Response(body, { status: 200 })
}

console.log(`HTTP server running. Access it at: http://localhost:8080/`)
Deno.serve({ port }, handler)
I have something similar with Oak:
import { Application, Router } from "oak"
import { operation } from "../utilities/operation.ts"
import { join } from "std/path/join.ts"

const PORT = 8000

const ROUTER = new Router()

ROUTER.get("/", (ctx) => {
ctx.response.type = "text/html"
ctx.response.body = Deno.readTextFileSync("./src/pages/index.html")
})

ROUTER.post("/", async (ctx) => {
const FORM_DATA = await ctx.request.body.formData()

try {
await operation({
"font-family": (FORM_DATA.get("font-family") ?? "") as string,
"css-content": (FORM_DATA.get("custom-css") ?? "") as string,
"restore-backup": FORM_DATA.has("restore-backup") as boolean,
})

ctx.response.redirect("/")
} catch (error: unknown) {
if (!(error instanceof Error)) throw error
ctx.response.body = error.message
}
})

const APP = new Application()

APP.use(ROUTER.routes())

APP.use(async (ctx, next) => {
try {
await ctx.send({
root: join(Deno.cwd(), "/src/static"),
})
} catch {
next()
}
})

console.log("Open the URL in your browser:")
console.log(`http://localhost:${PORT}`)

await APP.listen({ port: PORT })
import { Application, Router } from "oak"
import { operation } from "../utilities/operation.ts"
import { join } from "std/path/join.ts"

const PORT = 8000

const ROUTER = new Router()

ROUTER.get("/", (ctx) => {
ctx.response.type = "text/html"
ctx.response.body = Deno.readTextFileSync("./src/pages/index.html")
})

ROUTER.post("/", async (ctx) => {
const FORM_DATA = await ctx.request.body.formData()

try {
await operation({
"font-family": (FORM_DATA.get("font-family") ?? "") as string,
"css-content": (FORM_DATA.get("custom-css") ?? "") as string,
"restore-backup": FORM_DATA.has("restore-backup") as boolean,
})

ctx.response.redirect("/")
} catch (error: unknown) {
if (!(error instanceof Error)) throw error
ctx.response.body = error.message
}
})

const APP = new Application()

APP.use(ROUTER.routes())

APP.use(async (ctx, next) => {
try {
await ctx.send({
root: join(Deno.cwd(), "/src/static"),
})
} catch {
next()
}
})

console.log("Open the URL in your browser:")
console.log(`http://localhost:${PORT}`)

await APP.listen({ port: PORT })
The problem is that I don't get the longs in the console of the .exe when I run it. I don't get any errors, it's just a blank terminal. Does Oak does something behind the seen that breaks this? I can't use other frameworks if they don't have the same issue.
7 Replies
Deno AI Helper
Deno AI Helperโ€ข2mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the code snippet you provided, I noticed a couple of potential issues that might be causing problems when you compile your Deno Oak application to an .exe file. 1. In the Oak example, you are using Deno.readTextFileSync("./src/pages/index.html"). When you compile your application to an .exe, the file paths might not resolve correctly. Make sure that the path to index.html is correct and that the file is included in the compiled executable. 2. The catch block in your Oak router's POST handler uses next() without await. This should be await next(). However, this is unlikely to be the cause of the issue you're experiencing with the logs not appearing. 3. The await APP.listen({ port: PORT }) line starts the server. If there's an issue with the server starting up, you might not see any logs. Ensure that the port is not already in use and that your application has the necessary permissions to bind to that port. Please note that these suggestions are not based on the Deno documentation, and I advise you to double-check the accuracy of the advice given. If the issue persists, you may want to look into how the compilation process packages your application and whether all dependencies and resources are correctly included.
Leokuma
Leokumaโ€ข2mo ago
As bot said in item 1, it might be because Oak is trying to load something from the filesystem using a relative path
babakfp
babakfpโ€ข2mo ago
I fixed those up. I was going to send more info on this but Discord didn't allow me to send a screenshot. Even this code doesn't work (no console log and no errors):
import { Application } from "https://deno.land/x/oak@14.2.0/mod.ts"

new Application()

console.log("โœ… The HTTP server is running.")
import { Application } from "https://deno.land/x/oak@14.2.0/mod.ts"

new Application()

console.log("โœ… The HTTP server is running.")
Can someone check this out if they have the same issue on their system?
babakfp
babakfpโ€ข2mo ago
GitHub
Error: Cannot find module '../lightningcss.win32-x64-msvc.node' ยท p...
Hi ๐Ÿ‘‹ This error only happens when I compile my Deno project to a .exe file. In development, everything works fine. I don't know what is the deal with lightningcss.win32-x64-msvc.node. import { ...
pyrote
pyroteโ€ข2mo ago
I tried your example and some Oak code with a route and error handler. Neither runs correctly when compiled. Tried Deno 1.41.3 and 1.42.1 on Linux Devuan 5.10.0-28-amd64 #1 SMP Debian 5.10.209-2 (2024-01-31) x86_64 GNU/Linux Tried deno compile -r to reload the cache. When you run the compiled binaries under strace they are looking for files in the .cache directory of the user's home directory which seems odd. Other compiled Deno code doesn't do that. Then the binary is just hung on a epoll_wait() call.
stat("/home/deno_user/.cache/deno/node_analysis_cache_v1-journal", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
stat("/home/deno_user/.cache/deno/node_analysis_cache_v1-wal", 0x7ffcee483b20) = -1 ENOENT (No such file or directory)
fstat(10, {st_mode=S_IFREG|0644, st_size=36864, ...}) = 0
fcntl(10, F_SETLK, {l_type=F_UNLCK, l_whence=SEEK_SET, l_start=0, l_len=0}) = 0
...
epoll_wait(4, [{EPOLLIN, {u32=0, u64=0}}], 1024, -1) = 1
clock_gettime(CLOCK_MONOTONIC, {tv_sec=610859, tv_nsec=163549894}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=610859, tv_nsec=163926609}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=610859, tv_nsec=164308969}) = 0
epoll_wait(4,
stat("/home/deno_user/.cache/deno/node_analysis_cache_v1-journal", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
stat("/home/deno_user/.cache/deno/node_analysis_cache_v1-wal", 0x7ffcee483b20) = -1 ENOENT (No such file or directory)
fstat(10, {st_mode=S_IFREG|0644, st_size=36864, ...}) = 0
fcntl(10, F_SETLK, {l_type=F_UNLCK, l_whence=SEEK_SET, l_start=0, l_len=0}) = 0
...
epoll_wait(4, [{EPOLLIN, {u32=0, u64=0}}], 1024, -1) = 1
clock_gettime(CLOCK_MONOTONIC, {tv_sec=610859, tv_nsec=163549894}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=610859, tv_nsec=163926609}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=610859, tv_nsec=164308969}) = 0
epoll_wait(4,
babakfp
babakfpโ€ข2mo ago
Hey ๐Ÿ‘‹ Thank you for taking the time and taking a look into this! I removed Oak and switched to https://deno.land/x/abc@v1.3.3, it doesn't have the same issue and has a much cleaner API. Thanks again.
Mrcool
Mrcoolโ€ข2mo ago
Thats a weird bug
console.log(0);
await import("https://deno.land/x/oak@14.2.0/mod.ts");
console.log(1);
console.log(0);
await import("https://deno.land/x/oak@14.2.0/mod.ts");
console.log(1);
when compiled it get stuck at the import