Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jakubdonovan opened this issue Nov 10, 2022 · 8 comments
Open

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

jakubdonovan opened this issue Nov 10, 2022 · 8 comments

Comments

@jakubdonovan
Copy link

<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
Copy link

brocococonut commented Nov 15, 2022

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
Copy link
Contributor

jpaquim commented Nov 15, 2022

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: #6

@erlend-sh
Copy link

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
Copy link
Contributor

jpaquim commented Dec 28, 2022

@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
Copy link
Author

@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
Copy link
Contributor

jpaquim commented Jan 2, 2023

@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
Copy link

denoland/deno#17248

@jpaquim
Copy link
Contributor

jpaquim commented Jan 6, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants