D
Deno

help

compiled artifact can't find deno.json

Rrabbit_rabbit10/10/2023
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!
DAHDeno AI Helper10/10/2023
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. 🦕
Rrabbit_rabbit10/11/2023
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.
MMrcool10/11/2023
You can strace it to see where it's searching
LLeokuma10/16/2023
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

Looking for more? Join the community!