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
@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:
If the script executes in the browser there is no Deno namespace available as Deno is not the runtime running it, but the browser.
it's not executing in the browser, since the SvelteKit project is being generated as a static site
but let me double check
If you try and actually run the code, does it work?
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
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
i think it's falling back to using npm somehow
What does the tasks say in deno.json?
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:
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?
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
I was more asking for you to show me the error. Not describe to me the error

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
src/routes
missing Deno namespace comes up in the VS Code editor, and yeah
and yeah, this error instead is about static site generation
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?
no, it doesn't
so yeah, it might be unrelated