rabbit_rabbit
rabbit_rabbit•13mo ago

compiled artifact can't find deno.json

I'm using github actions to build and publish a binary like so
DENO_TLS_CA_STORE=system deno compile -A --unstable --target x86_64-unknown-linux-gnu --output binaries/web main.ts
DENO_TLS_CA_STORE=system deno compile -A --unstable --target x86_64-unknown-linux-gnu --output binaries/web main.ts
After downloading and unzipping the binary I noticed I have to add chmod +x web which is fine, but then I see
error: Uncaught (in promise) Error: Could not find a deno.json file in the current directory or any parent directory.
error: Uncaught (in promise) Error: Could not find a deno.json file in the current directory or any parent directory.
even if I'm running in a directory with a deno.json file. I'm running deno 1.37.0 Thanks in advance!
4 Replies
Deno AI Helper
Deno AI Helper•13mo ago
Based on the documentation, when you run a Deno command, Deno will try to find a configuration file (deno.json or deno.jsonc) by checking the current working directory and its parent directories in order. If none of the paths exist, Deno will run without applying any configuration. However, when you compile a Deno program into a standalone binary using deno compile, the binary does not retain the original file structure or the original working directory. Therefore, it cannot find the deno.json file in the current directory or any parent directory at runtime, even if it exists there. As a workaround, you might consider including all necessary configurations in your code before compiling it, or using environment variables to pass configuration at runtime. Please note that this information is not explicitly stated in the documentation, so it's a general advice. If you're still having issues, it might be helpful to provide more information about your deno.json file and how you're using it in your code. This could help identify any potential issues or misunderstandings. 🦕
rabbit_rabbit
rabbit_rabbit•13mo ago
Following up on the above, my deno.json file looks like this
{
"tasks": {
"compile": "DENO_TLS_CA_STORE=system deno compile -A --unsafely-ignore-certificate-errors --unstable --target x86_64-unknown-linux-gnu"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
},
"importMap": "./import_map.json"
}
{
"tasks": {
"compile": "DENO_TLS_CA_STORE=system deno compile -A --unsafely-ignore-certificate-errors --unstable --target x86_64-unknown-linux-gnu"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
},
"importMap": "./import_map.json"
}
I don't think this is at issue because for whatever reason it's not able to find the deno.json file despite the file being there in the folder in which the binary is being run.
Mrcool 🇵🇸
You can strace it to see where it's searching
Leokuma
Leokuma•13mo ago
If you can embed the JSON into the executable, you can try to --include the deno.json: https://docs.deno.com/runtime/manual/tools/compiler#dynamic-imports
Compiling Executables | Deno Docs
deno compile [--output ] will compile the script into a