bzm3r
bzm3r3w ago

Using Deno's readDir in a SvelteKit project?

If I have created a Svelte project using deno, and I am going to be static rendering it, can I use the Deno API in my typescript files? For example, suppose I want to call readDir?
17 Replies
bzm3r
bzm3rOP3w ago
@Doctor 🤖 so the situation is a little tricky i think i created a SvelteKit project using deno, and selected deno as the runtime during project creation then, i try to call something from the Deno namespace in a script in a Svelte component:
No description
fry69
fry693w ago
If the script executes in the browser there is no Deno namespace available as Deno is not the runtime running it, but the browser.
bzm3r
bzm3rOP3w ago
it's not executing in the browser, since the SvelteKit project is being generated as a static site but let me double check
Doctor 🤖
Doctor 🤖3w ago
If you try and actually run the code, does it work?
fry69
fry693w ago
Then either the editor might have a hard time digging through Svelte and Deno idioms, or the svelte pipeline uses a different runtime, e.g. Node.js
bzm3r
bzm3rOP3w ago
so when i run deno task dev --open, i see the following output: so clearly readDirSync is working ok but when i run deno task build it does not generate a static site successfully, so i think this is an issue on the Svelte side, yeah
No description
bzm3r
bzm3rOP3w ago
i think it's falling back to using npm somehow
Doctor 🤖
Doctor 🤖3w ago
What does the tasks say in deno.json?
bzm3r
bzm3rOP3w ago
there is no deno.json (so i am not entirely sure how it registers this as a deno project tbh) there is only a package.json:
No description
Doctor 🤖
Doctor 🤖3w ago
I'm not familiar with vite or svelte. So it might be using another runtime. What does the error say when it fails to build?
bzm3r
bzm3rOP3w ago
i am making sure to remove npm the error is kinda long and opaque, yeah so let me make sure there is no other runtime for it to fallback onto first
Doctor 🤖
Doctor 🤖3w ago
I was more asking for you to show me the error. Not describe to me the error
bzm3r
bzm3rOP3w ago
No description
Doctor 🤖
Doctor 🤖3w ago
Is the file you showed early where you used Deno.readDir, src/routes or sec/routes/t0? That error also doesn't read like it would be missing the Deno namespace api
bzm3r
bzm3rOP3w ago
src/routes missing Deno namespace comes up in the VS Code editor, and yeah and yeah, this error instead is about static site generation
Doctor 🤖
Doctor 🤖3w ago
The error in your editor and the error when running could very much be unrelated. Does the site build when you remove the Deno keyword use?
bzm3r
bzm3rOP3w ago
no, it doesn't so yeah, it might be unrelated

Did you find this page helpful?