NeubekiN
Deno9mo ago
1 reply
Neubeki

Cannot read `include`d folder in compiled file

Hello, I am trying to compile an application and read a folder that I include with it. I am running into a problem with the output. I don't know how to read a directory inside the binary that I have included. I ran this command deno compile --include config to include the folder config in the binary, but I don't know how to read it and where to find it.

This is my folder structure:

.
├── main.ts
├── deno.json
└── config/
    ├── .env
    └── settings.json


And running deno task dev can read the file, because everything is where it is expected. If I compile the program and run it from this folder, I can also access the directory, because the file is where it is supposed to relative to the 'config' folder.

I want to have the config folder included though, so I can move the file freely around.

Here's a sample program:

console.log("Attempting to read included 'config' directory...");

const configDir = "./config";
console.log(`Deno Version: ${Deno.version.deno}`);
console.log(`Attempting to access path: ${configDir}`);

try {
  console.log("\nDirectory contents:");
  for await (const dirEntry of Deno.readDir(configDir)) {
    console.log(
      `- ${dirEntry.name} (${dirEntry.isDirectory ? "dir" : "file"})`,
    );
  }
} catch (error) {
  console.error("Error reading directory:", error);
}


EDIT: My full example includes using deno workspaces and the file that reads the config folder is in another workspace than the one calling it. Which might introduce extra complexity
Was this page helpful?