pluvial / svelte-adapter-deno

A SvelteKit adapter for Deno
https://svelte-adapter-deno.deno.dev/
MIT License
313 stars 14 forks source link

Unable to use Deno inside a components' script tags #32

Open jakubdonovan opened 1 year ago

jakubdonovan commented 1 year ago
<script>
    const res = await fetch('https://example-29544e.webflow.io');
</script>

produces the following error

Cannot use keyword 'await' outside an async functionsvelte(parse-error) 'await' expressions are only allowed within async functions and at the top levels of modules.js(1308)

I started my development server via npm run dev but it looks like it's still running node rather than Deno. Can I get some help?

brocococonut commented 1 year ago

Any script using npm will be using Node by default. NPM is the "Node Package Manager"

Deno will only work in production when you've run npm run build and have started the resulting server with something along the lines of deno run -A build/index.js Note: the above script bypasses a lot of the security of Deno, you'll want to use more granulated permissions like with the following command: deno run --allow-net --allow-env --allow-read build/index.js

To reiterate though, the adapter can't be used for development... It can only help output files used in production

That being said, some more context on what you're trying to do would be helpful as it's likely something unrelated. If you have a repo I could check out, I'd be happy to take a look!

jpaquim commented 1 year ago

To add a little bit to what @brocococonut mentioned, this might change in the future, with the recent stabilization of npm support in Deno, and in particular with them getting Vite successfully running in Deno: https://deno.com/blog/v1.28 https://github.com/bartlomieju/vite-deno-example

Both should make it possible to run the end-to-end development process using Deno, but that is of a wider scope than what I had planned for this adapter. Related discussion in the past: https://github.com/pluvial/svelte-adapter-deno/issues/6

erlend-sh commented 1 year ago

that is of a wider scope than what I had planned for this adapter.

Has your stance on this changed somewhat? I see the repo description now says β€œA SvelteKit adapter for Deno”, with a tag to match πŸ˜‰

jpaquim commented 1 year ago

@erlend-sh now that the Deno team have managed to get Vite itself running under Deno's compatibility layer for Node, I think it's worth trying to get the whole thing running end-to-end in Deno, yes.

However, that may not necessarily result in any changes to this adapter specifically, as it is still "only" a SvelteKit adapter, and as such is Node-first. For example, when using the adapters for Cloudflare, Vercel, Netlify, etc., the development experience doesn't change, vite dev will still run in Node as usual, only the production build is targeted for a specific environment. In that sense, the primary goal of svelte-adapter-deno is aligning with whatever the other official @sveltejs/adapter-* are doing, not exactly doing the full "SvelteKit on Deno" experience which is what I understand you're asking for πŸ™‚

jakubdonovan commented 1 year ago

@erlend-sh now that the Deno team have managed to get Vite itself running under Deno's compatibility layer for Node, I think it's worth trying to get the whole thing running end-to-end in Deno, yes.

However, that may not necessarily result in any changes to this adapter specifically, as it is still "only" a SvelteKit adapter, and as such is Node-first. For example, when using the adapters for Cloudflare, Vercel, Netlify, etc., the development experience doesn't change, vite dev will still run in Node as usual, only the production build is targeted for a specific environment. In that sense, the primary goal of svelte-adapter-deno is aligning with whatever the other official @sveltejs/adapter-* are doing, not exactly doing the full "SvelteKit on Deno" experience which is what I understand you're asking for πŸ™‚

So how do we get it sveltekit and deno running during live development now that vite works with deno?

jpaquim commented 1 year ago

@jakubdonovan after the architecture changes a few months ago, SvelteKit is now "just" a Vite plugin , so in theory if Vite runs fine under Deno, then you should just be able to run it with the SvelteKit plugin and it should work end-to-end in Deno. I haven't tried this myself, but I do want to experiment with that at some point.

erlend-sh commented 1 year ago

https://github.com/denoland/deno/issues/17248

jpaquim commented 1 year ago

@erlend-sh thank you for the pointer, I'm also tracking that issue and some of the discussion in the Deno Discord, after starting to experiment with SvelteKit on Deno here: https://github.com/jpaquim/sveltekit-deno

Unfortunately the patch in my repo still seems to be needed, as the PR mentioned in that issue doesn't seem to have fixed yet.